Submission #3026264
Source Code Expand
#!/usr/bin/python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def main(): N, M = map(int, input().split()) m = defaultdict(list) for _ in range(M): L, R, D = map(int, input().split()) L -= 1 R -= 1 m[L].append((R, D)) m[R].append((L, -D)) x = [None] * N for k in range(N): if x[k] is not None: continue x[k] = 0 que = deque() que.append(k) while len(que) != 0: i = que.popleft() for j, d in m[i]: if x[j] is None: x[j] = x[i] + d que.append(j) else: if x[j] != x[i] + d: print(No) return print(Yes) if __name__ == '__main__': main()
Submission Info
Submission Time | |
---|---|
Task | D - People on a Line |
User | MitI_7 |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 1361 Byte |
Status | AC |
Exec Time | 1136 ms |
Memory | 72148 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 947 ms | 69628 KB |
02.txt | AC | 1131 ms | 70220 KB |
03.txt | AC | 1007 ms | 68720 KB |
04.txt | AC | 1136 ms | 70668 KB |
05.txt | AC | 850 ms | 62620 KB |
06.txt | AC | 881 ms | 57720 KB |
07.txt | AC | 843 ms | 61312 KB |
08.txt | AC | 813 ms | 55332 KB |
09.txt | AC | 723 ms | 52220 KB |
10.txt | AC | 697 ms | 50808 KB |
11.txt | AC | 686 ms | 51044 KB |
12.txt | AC | 730 ms | 54464 KB |
13.txt | AC | 937 ms | 60760 KB |
14.txt | AC | 754 ms | 53272 KB |
15.txt | AC | 741 ms | 54588 KB |
16.txt | AC | 725 ms | 53136 KB |
17.txt | AC | 1059 ms | 65904 KB |
18.txt | AC | 978 ms | 62532 KB |
19.txt | AC | 779 ms | 55516 KB |
20.txt | AC | 779 ms | 55536 KB |
21.txt | AC | 942 ms | 65288 KB |
22.txt | AC | 699 ms | 53188 KB |
23.txt | AC | 915 ms | 64836 KB |
24.txt | AC | 707 ms | 53120 KB |
25.txt | AC | 1079 ms | 72148 KB |
26.txt | AC | 1051 ms | 65384 KB |
27.txt | AC | 660 ms | 50252 KB |
28.txt | AC | 813 ms | 55696 KB |
29.txt | AC | 643 ms | 50256 KB |
30.txt | AC | 775 ms | 53560 KB |
31.txt | AC | 637 ms | 50256 KB |
32.txt | AC | 750 ms | 53616 KB |
33.txt | AC | 1060 ms | 71572 KB |
34.txt | AC | 979 ms | 65376 KB |
35.txt | AC | 652 ms | 50256 KB |
36.txt | AC | 739 ms | 53796 KB |
37.txt | AC | 626 ms | 50276 KB |
38.txt | AC | 715 ms | 52672 KB |
39.txt | AC | 567 ms | 47736 KB |
40.txt | AC | 745 ms | 53208 KB |
41.txt | AC | 106 ms | 22252 KB |
42.txt | AC | 322 ms | 22012 KB |
sample01.txt | AC | 27 ms | 3956 KB |
sample02.txt | AC | 27 ms | 3952 KB |
sample03.txt | AC | 26 ms | 3952 KB |
sample04.txt | AC | 26 ms | 3956 KB |
sample05.txt | AC | 26 ms | 3956 KB |