Problem Statement
Ringo has a tree with
Here, we define
We will consider a complete graph
Constraints
- The given graph is a tree.
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the cost of the minimum spanning tree of
Sample Input 1
Copy
4
1 3 5 1
1 2 1
2 3 2
3 4 3
Sample Output 1
Copy
22
We connect the following pairs: Vertex
Sample Input 2
Copy
6
44 23 31 29 32 15
1 2 10
1 3 12
1 4 16
4 5 8
4 6 15
Sample Output 2
Copy
359
Sample Input 3
Copy
2
1000000000 1000000000
2 1 1000000000
Sample Output 3
Copy
3000000000
Comments