Every season at the mountain city of Highreach, someone must prove the quality of the harvest. This year the task falls to Devi, armed only with the bridges register. Task: Print the minimum total weight of a spanning tree, or -1 if the graph is not connected. Input format: First line: n and m. Next m lines: u v w. Output format: Print the MST weight or -1. Constraints: 1 <= n <= 1080; 0 <= m <= 3240; 0 <= w <= 1000.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 1080; 0 <= m <= 3240; 0 <= w <= 1000.
