KOICOST - Cost
You are given an undirected graph with N verticies and M edges, where the weights are unique.
There is a function Cost(u, v), which is defined as follows:
While there is a path between vertex u and v, delete the edge with the smallest weight. Cost(u,v) is the sum of the weights of the edges that were deleted in this process.
For example, from the graph above (same as the sample input), Cost(2,6) is 2+3+4+5+6 = 20.
Given an undirected graph, your task is to calculate the sum of Cost(u,v) for all vertices u and v, where u < v. Since the answer can get large, output the answer modulo 10^9.
The first line of the input consists of two integers, N and M. (1 <= N <= 100,000, 0 <= M <= 100,000)
The next M lines consists of three integers, u, v, and w. This means that there is an edge between vertex u and v with weight w. (1 <= u, v <= N, 1 <= w <= 100,000)
Output the sum specified in the problem statement.
Input: 6 7
1 2 10
2 3 2
4 3 5
6 3 15
3 5 4
4 5 3
2 6 6
best problem of dsu on spoj .............
got a wa bcz of this incomplete input statement :(.
Statement is incomplete :/ you need to print the answer modulo 10^9
don't use vector . it causes a segment fault
seems to get NZEC in java ,are the constraints correctly specified?
Who can tell me that when I input:
Please update the problem for the Modulo and also the statement seems incomplete in the last line before the "Input" section.
Thanks! This modulo...
Thanks @Rajat De :)