Submit solution

Points: 100
Time limit: 2.0s
Python 3 5.0s
Memory limit: 940M

Author:
Problem type

You are tasked with finding the Minimum Spanning Tree of a Graph.

Input Format

The first line of input will consist of two integers, n and m (n \le 10^5, m \le 2\times 10^5). The next m lines will consist of three integers a b and c, representing an undirected edge between nodes a and b with weight c.

Output Format

Output a single integer, the weight of the MST of the given graph. If there is no MST, output -1.

Sample Input 1

3 4
1 2 5
1 3 6
2 3 2
2 1 3

Sample Output 1

5

Sample Explanation 1

The MST is constructed with the edges (2,1,3) and (2,3,2).


Comments

There are no comments at the moment.