luogu#P5631. 最小mex生成树

    ID: 4220 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树并查集O2优化分治动态树 LCT

最小mex生成树

Background

This is a classic problem.

Problem Description

Given an undirected connected graph with nn vertices and mm edges, each edge has a weight.

Define the mex\text{mex} of a set of natural numbers SS as the smallest natural number that does not appear in SS.

Now you need to find a spanning tree of this graph such that the mex\text{mex} of the set of its edge weights is as small as possible.

Input Format

The first line contains two positive integers n,mn, m.

The next mm lines each contain three non-negative integers u,v,wu, v, w, indicating that there is an edge between uu and vv with weight ww.

Output Format

Output one line with one natural number, representing the minimum possible mex\text{mex} value.

3 3
1 2 0
2 3 1
3 2 2

1

Hint

Constraints

  • For 20%20\% of the testdata, 1n1001 \le n \le 100, 1m2001 \le m \le 200.
  • For 50%50\% of the testdata, 1n20001 \le n \le 2000, 1m30001 \le m \le 3000.
  • For 80%80\% of the testdata, 1n1051 \le n \le 10^5, 1m2×1051 \le m \le 2 \times 10^5.
  • For 100%100\% of the testdata, 1n1061 \le n \le 10^6, 1m2×106,0w1051 \le m \le 2 \times 10^6, 0 \le w \le 10^5.

The input size is large, so an efficient input method is recommended.

Translated by ChatGPT 5