This page is still under construction.

Parts of this page are still being built. What you see may change.

Graph and Minimum Spanning Tree

Time limit2sMemory limit512 MB

Summary
For each edge of a connected weighted undirected graph, print the weight of a minimum spanning tree that is forced to include that edge.
Level

Hard8 of 10

Topics
Minimum spanning tree, Union-find, Tree, DFS
Solved
No attempts yet

Problem

You are given a connected, undirected, weighted graph GG with NN vertices and MM edges. GG has no self-loops, and at most one edge joins any pair of vertices.

For each edge (u,v)(u, v), compute the total weight of a minimum spanning tree that is forced to contain that edge.

Input

The first line contains the number of vertices NN and the number of edges MM (2≤N≤2000002 \le N \le 200000, N−1≤M≤200000N-1 \le M \le 200000).

Each of the next MM lines contains the edge information uu, vv, ww, meaning that the edge joining vertex uu and vertex vv has weight ww (1≤u,v≤N1 \le u, v \le N, u≠vu \ne v, 1≤w≤1091 \le w \le 10^9).

Output

For each edge, print the total weight of a minimum spanning tree containing that edge, one per line. Print the answers in the order the edges are given in the input.

Examples2

  1. Example 1

    Input
    5 8
    1 2 5
    2 3 4
    1 3 2
    3 4 8
    4 5 3
    3 5 6
    1 4 9
    2 5 1
    
    Expected output
    11
    10
    10
    14
    10
    12
    15
    10
    
  2. Example 2

    Input
    6 8
    1 2 2
    2 3 8
    3 4 1
    4 1 9
    4 5 7
    5 6 2
    6 4 6
    3 6 9
    
    Expected output
    19
    19
    19
    20
    20
    19
    19
    22