Jonathan Sumabat has been given a puzzle by his teacher that he is unable to solve. Can you help him?
The minimum spanning tree of a graph is a subgraph that connects every node using the minimum total cost. The cost of a minimum spanning tree is equal to the sum of all its edges. Given a connected graph, help Jonathan Sumabat find the cost of a minimum spanning tree for it.
Input Specification
The first line is representing the number of nodes in this graph. The nodes are numbered to .
The next lines represent an edge in the graph. Every edge in the graph will be listed here.
- The first two integers are representing a bidirectional edge connecting node number with .
- The third integer is representing the cost of this edge.
It is guaranteed that this tree is connected, meaning that there is a path to every other node from any node in this graph.
Output Specification
Output the cost of this graph's minimum spanning tree.
Comments