#ARC090B. [ABC087D] People on a Line

[ABC087D] People on a Line

Score : 400400 points

Problem Statement

There are NN people standing on the xx-axis. Let the coordinate of Person ii be xix_i. For every ii, xix_i is an integer between 00 and 10910^9 (inclusive). It is possible that more than one person is standing at the same coordinate.

You will given MM pieces of information regarding the positions of these people. The ii-th piece of information has the form (Li,Ri,Di)(L_i, R_i, D_i). This means that Person RiR_i is to the right of Person LiL_i by DiD_i units of distance, that is, xRixLi=Dix_{R_i} - x_{L_i} = D_i holds.

It turns out that some of these MM pieces of information may be incorrect. Determine if there exists a set of values (x1,x2,...,xN)(x_1, x_2, ..., x_N) that is consistent with the given pieces of information.

Constraints

  • 1N1001 \leq N \leq 100 000000
  • 0M2000 \leq M \leq 200 000000
  • 1Li,RiN1 \leq L_i, R_i \leq N (1iM1 \leq i \leq M)
  • 0Di100 \leq D_i \leq 10 000000 (1iM1 \leq i \leq M)
  • LiRiL_i \neq R_i (1iM1 \leq i \leq M)
  • If iji \neq j, then (Li,Ri)(Lj,Rj)(L_i, R_i) \neq (L_j, R_j) and (Li,Ri)(Rj,Lj)(L_i, R_i) \neq (R_j, L_j).
  • DiD_i are integers.

Input

Input is given from Standard Input in the following format:

NN MM

L1L_1 R1R_1 D1D_1

L2L_2 R2R_2 D2D_2

::

LML_M RMR_M DMD_M

Output

If there exists a set of values (x1,x2,...,xN)(x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.

3 3
1 2 1
2 3 1
1 3 2
Yes

Some possible sets of values (x1,x2,x3)(x_1, x_2, x_3) are (0,1,2)(0, 1, 2) and (101,102,103)(101, 102, 103).

3 3
1 2 1
2 3 1
1 3 5
No

If the first two pieces of information are correct, x3x1=2x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.

4 3
2 1 1
2 3 5
3 4 2
Yes
10 3
8 7 100
7 9 100
9 8 100
No
100 0
Yes