#abc373d. D - Hidden Weights(waiting SPJ)

D - Hidden Weights(waiting SPJ)

Score : 400400 points

问题陈述

给定一个有向图,包含 NN 个顶点和 MM 条边。第 jj 条有向边从顶点 uju_j 指向顶点 vjv_j,并且有权重 wjw_j

找到一种方法,为每个顶点写上一个介于 1018-10^{18}101810^{18} 之间的整数,以满足以下条件。

  • xix_i 为写在顶点 ii 上的值。对于所有边 j=1,2,,Mj=1,2,\dots,M,满足 xvjxuj=wjx_{v_j} - x_{u_j} = w_j

保证对于给定的输入至少存在一种这样的分配。

以上为大语言模型 kimi 翻译,仅供参考。

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