#C1768. Edge Weight Sum Computation

    ID: 45009 Type: Default 1000ms 256MiB

Edge Weight Sum Computation

Edge Weight Sum Computation

You are given an undirected graph with N nodes and M edges. Each edge has an associated weight. For each node i, define the sum:

\(g(i)=\sum_{\text{edge } e \text{ incident to } i} w_e\)

Your task is to compute g(1), g(2), …, g(N) for each test case. The graph is not necessarily connected, and there might be nodes with no incident edges.

Input and Output are handled via standard input and output respectively.

inputFormat

The first line of input contains an integer T representing the number of test cases.

Each test case consists of:

  • A line with two space-separated integers N and M -- the number of nodes and the number of edges.
  • M subsequent lines, each containing three space-separated integers u, v and w, which represent an undirected edge between nodes u and v with weight w.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 105
  • 0 ≤ M ≤ 106
  • 1 ≤ u, v ≤ N
  • 1 ≤ w ≤ 105

outputFormat

For each test case, output a single line with N space-separated integers representing g(1), g(2), …, g(N).

## sample
2
3 3
1 2 4
2 3 5
1 3 7
4 2
1 2 10
3 4 20
11 9 12

10 10 20 20

</p>