Sum of distances
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
A weighted tree with vertices and edges is given. The distance between vertices and is defined as the weight of the smallest edge on the path between and .
Find the sum of distances between all pairs of vertices in the tree.
Input
The first line contains the number of vertices in the graph. The next lines describe the edges. Each line contains three integers: the numbers of vertices connected by the edge (vertices are numbered from to ) and the weight of the edge.
Output
Print the sum of distances between all pairs of vertices in the tree.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 115
Acceptance rate 40%