luogu#P5631. 最小mex生成树
最小mex生成树
Background
This is a classic problem.
Problem Description
Given an undirected connected graph with vertices and edges, each edge has a weight.
Define the of a set of natural numbers as the smallest natural number that does not appear in .
Now you need to find a spanning tree of this graph such that the of the set of its edge weights is as small as possible.
Input Format
The first line contains two positive integers .
The next lines each contain three non-negative integers , indicating that there is an edge between and with weight .
Output Format
Output one line with one natural number, representing the minimum possible value.
3 3
1 2 0
2 3 1
3 2 2
1
Hint
Constraints
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
The input size is large, so an efficient input method is recommended.
Translated by ChatGPT 5