Minimum spanning tree#705

Minimum spanning tree

1 second
128 megabytes
Medium (≈1350)

Find the weight of the minimum spanning tree for an undirected weighted connected graph.

Input

The first line contains the number of vertices and m~(1 \le n \le 100, 1 \le m \le 6000) edges in the graph. Each of the following lines contains a triplet of numbers a, b, c, where and are the vertex numbers connected by an edge, and is the weight of the edge (a positive integer not exceeding ).

Output

Print the weight of the minimum spanning tree.

Examples

Example 1

Loading
Loading