Type: Default 2000ms 256MiB

Hidden Weights

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Problem Statement

You are given a directed graph with NN vertices and MM edges. The jj-th directed edge goes from vertex uju_j to vertex vjv_j and has a weight of wjw_j.

Find one way to write an integer between 1018-10^{18} and 101810^{18}, inclusive, to each vertex such that the following condition is satisfied.

  • Let xix_i be the value written on vertex ii. For all edges j=1,2,,Mj=1,2,\dots,M, it holds that xvjxuj=wjx_{v_j} - x_{u_j} = w_j.

It is guaranteed that at least one such assignment exists for the given input.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1Mmin{2×105,N(N1)/2}1 \leq M \leq \min\{2 \times 10^5,N(N-1)/2\}
  • 1uj,vjN1 \leq u_j, v_j \leq N
  • ujvju_j \neq v_j
  • If iji \neq j, then (ui,vi)(uj,vj)(u_i, v_i) \neq (u_j, v_j) and (ui,vi)(vj,uj)(u_i, v_i) \neq (v_j, u_j)
  • wj109|w_j| \leq 10^9
  • All input values are integers.
  • There exists at least one assignment satisfying the conditions.

Input

The input is given from Standard Input in the following format:

NN MM

u1u_1 v1v_1 w1w_1

u2u_2 v2v_2 w2w_2

\vdots

uMu_M vMv_M wMw_M

Output

Let xix_i be the integer written on vertex ii. Print x1,x2,,xNx_1, x_2, \dots, x_N in this order, separated by spaces, on a single line. If there are multiple solutions, you may print any of them.

Sample Input 1

3 3
1 2 2
3 2 3
1 3 -1

Sample Output 1

3 5 2

By setting x=(3,5,2)x = (3, 5, 2), we have x2x1=w1=2x_2 - x_1 = w_1 = 2, x2x3=w2=3x_2 - x_3 = w_2 = 3, x3x1=w3=1x_3 - x_1 = w_3 = -1, satisfying the conditions.

For example, x=(1,1,2)x = (-1, 1, -2) is also a valid answer.

Sample Input 2

4 2
2 1 5
3 4 -3

Sample Output 2

5 0 6 3

For example, x=(0,5,4,1)x = (0, -5, 4, 1) and x=(5,0,4,1)x = (5, 0, 4, 1) are also valid answers.

Sample Input 3

5 7
2 1 18169343
3 1 307110901
4 1 130955934
2 3 -288941558
2 5 96267410
5 3 -385208968
4 3 -176154967

Sample Output 3

200401298 182231955 -106709603 69445364 278499365

SDNU_ACM_ICPC_2024_WEEKLY_PRACTICE_1st

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2024-10-27 18:30
End at
2024-10-27 21:30
Duration
3 hour(s)
Host
Partic.
39