atcoder#ARC090B. [ABC087D] People on a Line
[ABC087D] People on a Line
Score : points
Problem Statement
There are people standing on the -axis. Let the coordinate of Person be . For every , is an integer between and (inclusive). It is possible that more than one person is standing at the same coordinate.
You will given pieces of information regarding the positions of these people. The -th piece of information has the form . This means that Person is to the right of Person by units of distance, that is, holds.
It turns out that some of these pieces of information may be incorrect. Determine if there exists a set of values that is consistent with the given pieces of information.
Constraints
- ()
- ()
- ()
- If , then and .
- are integers.
Input
Input is given from Standard Input in the following format:
Output
If there exists a set of values 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 are and .
3 3
1 2 1
2 3 1
1 3 5
No
If the first two pieces of information are correct, 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