QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#600. Minimum MEX Spanning Tree

統計

You are given a connected undirected graph with $n$ vertices and $m$ edges. The $i$-th edge has a non-negative integer weight $w_i$. Find a spanning tree of the graph such that the mex of the set of edge weights in the spanning tree is as small as possible.

Input

The first line of the input contains two positive integers $n$ and $m$ ($1 \le n \le 5 \times 10^5$, $1 \le m \le 10^6$).

The next $m$ lines each contain three non-negative integers $u$, $v$, and $w$ ($1 \le u, v \le n$, $u \ne v$ $0 \le w \le n-1$), indicating that there is an edge between vertices $u$ and $v$ with weight $w$.

Output

Output a single line with a single integer, indicating the answer.

Example

Input

2 2
1 2 0
1 2 1

Output

0

Input

5 7
1 2 0
1 3 0
2 4 1
2 5 0
3 4 2
3 5 0
4 5 1

Output

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.