#icpc2013springe. [icpc2013spring_e]Minimum Spanning Tree
[icpc2013spring_e]Minimum Spanning Tree
$(function(){document.getElementById("fixed-server-timer").style.display = "none";})
Problem Statement
You are given an undirected weighted graph with nodes and edges. Each edge is numbered from to .
Let be an graph that is made by erasing -th edge from . Your task is to compute the cost of minimum spanning tree in for each .
Input
The dataset is formatted as follows.
...
The first line of the input contains two integers () and (). is the number of nodes and is the number of edges in the graph. Then lines follow, each of which contains (), () and (). This means that there is an edge between node and node and its cost is . It is guaranteed that the given graph is simple: That is, for any pair of nodes, there is at most one edge that connects them, and for all .
Output
Print the cost of minimum spanning tree in for each , in line. If there is no spanning trees in , print "-1" (quotes for clarity) instead.
Sample Input 1
4 6
1 2 2
1 3 6
1 4 3
2 3 1
2 4 4
3 4 5
Output for the Sample Input 1
8
6
7
10
6
6
Sample Input 2
4 4
1 2 1
1 3 10
2 3 100
3 4 1000
Output for the Sample Input 2
1110
1101
1011
-1
Sample Input 3
7 10
1 2 1
1 3 2
2 3 3
2 4 4
2 5 5
3 6 6
3 7 7
4 5 8
5 6 9
6 7 10
Output for the Sample Input 3
27
26
25
29
28
28
28
25
25
25
Sample Input 4
3 1
1 3 999
Output for the Sample Input 4
-1
Source Name
Japan Alumni Group Spring Contest 2013