Submission #2793710


Source Code Expand

n, m = map(int, input().split())
xs = [tuple(map(int, input().split())) for _ in range(m)]

union = {x:(x, 0) for x in range(1, n+1)}
def root(n):
    if union[n][0] == n:
        return union[n]
    n1, d1 = union[n]
    n2, d2 = root(n1)
    union[n] = (n2, d2+d1)
    return union[n]

for l, r, d in xs:
    n1, d1 = root(l)
    n2, d2 = root(r)
    if n1 != n2:
        union[n2] = (n1, d + d1 - d2)
    elif d != d2 - d1:
        print('No')
        break
else:
    print('Yes')

Submission Info

Submission Time
Task D - People on a Line
User zehnpaard
Language Python (3.4.3)
Score 400
Code Size 504 Byte
Status AC
Exec Time 1296 ms
Memory 53108 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 47
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
Case Name Status Exec Time Memory
01.txt AC 656 ms 49188 KB
02.txt AC 1285 ms 49196 KB
03.txt AC 748 ms 50156 KB
04.txt AC 1296 ms 50204 KB
05.txt AC 648 ms 47168 KB
06.txt AC 906 ms 43020 KB
07.txt AC 653 ms 46384 KB
08.txt AC 842 ms 41360 KB
09.txt AC 714 ms 38980 KB
10.txt AC 685 ms 37988 KB
11.txt AC 608 ms 38476 KB
12.txt AC 574 ms 41216 KB
13.txt AC 956 ms 43936 KB
14.txt AC 757 ms 39828 KB
15.txt AC 603 ms 41272 KB
16.txt AC 785 ms 39940 KB
17.txt AC 1150 ms 47004 KB
18.txt AC 999 ms 45208 KB
19.txt AC 878 ms 41400 KB
20.txt AC 853 ms 41372 KB
21.txt AC 759 ms 47108 KB
22.txt AC 649 ms 40768 KB
23.txt AC 711 ms 47176 KB
24.txt AC 622 ms 40680 KB
25.txt AC 1260 ms 53108 KB
26.txt AC 1186 ms 46964 KB
27.txt AC 568 ms 39328 KB
28.txt AC 880 ms 41572 KB
29.txt AC 544 ms 39264 KB
30.txt AC 779 ms 39940 KB
31.txt AC 559 ms 39300 KB
32.txt AC 779 ms 40028 KB
33.txt AC 956 ms 52748 KB
34.txt AC 730 ms 47076 KB
35.txt AC 543 ms 39332 KB
36.txt AC 640 ms 40712 KB
37.txt AC 545 ms 39344 KB
38.txt AC 627 ms 39452 KB
39.txt AC 545 ms 39244 KB
40.txt AC 656 ms 39364 KB
41.txt AC 45 ms 20588 KB
42.txt AC 374 ms 30196 KB
sample01.txt AC 17 ms 3064 KB
sample02.txt AC 17 ms 3064 KB
sample03.txt AC 17 ms 3064 KB
sample04.txt AC 17 ms 3064 KB
sample05.txt AC 17 ms 3064 KB