Jarl inherited the observatory at the poppy fields of Scarlet Plain along with its curious bookkeeping system for tunnels. Time to make sense of it. 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 <= 996; 0 <= m <= 2988; 0 <= w <= 1000000.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 996; 0 <= m <= 2988; 0 <= w <= 1000000.
