There are many ideas for this question. Here we only introduce one idea: the general idea of the Kruskal algorithm: First sorting, then using and querying the connected edge of the set,Final output maximum Edge Weight.
Sort (E + 1, E + 1 + M, CMP); For (INT I = 1; I <= m; ++ I) {f = find (E [I]. f); t = find (E [I]. t); If (F! = T) {B [f] = T; ++ CNT; W = find (1); If (t = W) {for (Int J = 2; j <= N; ++ J) {If (OK [J] = false & find (j) = W) {ans [J] = E [I]. w; OK [J] = true ;}}if (CNT = N-1) {break ;}}}}
Q1: Why is Kruskal used in this question )? A1: you only need to determine whether each vertex is connected to $1 $ when the maximum spanning tree is generated. If yes, then his answer is the current edge (because the edge is arranged in ascending order of weight, and the current edge is the smallest edge between the current vertex and $1 $ ).
Solution 20181029 test: T4 Ambassador