#c22605. Minimum spanning tree for each edge

Minimum spanning tree for each edge

Minimum Spanning Tree for Each Edge

Problem Background

CF 609E

Problem Description

Given an undirected weighted simple graph with nn vertices and mm edges, with vertices numbered from 11 to nn, for each edge compute the minimum total weight of a spanning tree that contains this edge.

Input Format

The first line contains two integers n,mn, m, the number of vertices and edges.

The next mm lines each contain three integers u,v,wu, v, w, meaning there is an edge of weight ww between vertex uu and vertex vv.

Output Format

Output mm lines in total; the ii-th line contains one integer, the minimum total weight of a spanning tree containing the ii-th edge.

Sample Input

5 7
1 2 3
1 3 1
1 4 5
2 3 2
2 5 3
3 4 2
4 5 4

Sample Output

9
8
11
8
8
8
9

Constraints

For 100%100\% of the data: 1≤n≤2×1051 \leq n \leq 2\times 10^5, n−1≤m≤2×105n-1 \leq m \leq 2\times 10^5, 1≤u,v≤n1 \leq u, v \leq n, 1≤w≤1091 \leq w \leq 10^9. The graph is guaranteed to be connected.