#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 GG with nn nodes and mm edges. Each edge is numbered from 11 to mm.

Let GiG_i be an graph that is made by erasing ii-th edge from GG. Your task is to compute the cost of minimum spanning tree in GiG_i for each ii.


Input

The dataset is formatted as follows.

nn mm a1a_1 b1b_1 w1w_1 ... ama_m bmb_m wmw_m

The first line of the input contains two integers nn (2leqnleq100,0002 \\leq n \\leq 100{,}000) and mm (1leqmleq200,0001 \\leq m \\leq 200{,}000). nn is the number of nodes and mm is the number of edges in the graph. Then mm lines follow, each of which contains aia_i (1leqaileqn1 \\leq a_i \\leq n), bib_i (1leqbileqn1 \\leq b_i \\leq n) and wiw_i (0leqwileq1,000,0000 \\leq w_i \\leq 1{,}000{,}000). This means that there is an edge between node aia_i and node bib_i and its cost is wiw_i. 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 aineqbia_i \\neq b_i for all ii.

Output

Print the cost of minimum spanning tree in GiG_i for each ii, in mm line. If there is no spanning trees in GiG_i, 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