Every season at the wren hedges of Thimblewick, someone must rebuild the damaged itinerary. This year the task falls to Bishop, armed only with the corridors 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 <= 1000; 0 <= m <= 3000; 0 <= w <= 10.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 1000; 0 <= m <= 3000; 0 <= w <= 10.
