Jonathan Sumabat 7.5

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Java 8 2.0s
Memory limit: 64M

Author:
Problem type

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 n (2 \le n \le 10^5) representing the number of nodes in this graph. The nodes are numbered 0 to n-1.
The next n-1 lines represent an edge in the graph. Every edge in the graph will be listed here.

  • The first two integers are m_1, m_2 representing a bidirectional edge connecting node number m_1 with m_2.
  • The third integer is m_3 (1 \le |m_3| \le 1000) 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

There are no comments at the moment.