285. Minimum Spanning Tree
MediumKruskalUnion-Find
Print the total weight of a minimum spanning tree of the connected undirected weighted graph.
Input format
Line 1: n m Next m lines: u v w
Output format
The MST weight.
Example 1
Input
4 5 1 2 10 1 3 6 1 4 5 2 4 15 3 4 4
Output
19
Example 2
Input
2 1 1 2 7
Output
7
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…