結果
問題 | No.1023 Cyclic Tour |
ユーザー | ああいい |
提出日時 | 2022-01-27 23:21:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,288 bytes |
コンパイル時間 | 243 ms |
コンパイル使用メモリ | 82,028 KB |
実行使用メモリ | 156,048 KB |
最終ジャッジ日時 | 2024-06-07 21:09:33 |
合計ジャッジ時間 | 34,029 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,528 KB |
testcase_01 | AC | 41 ms
54,916 KB |
testcase_02 | AC | 41 ms
55,232 KB |
testcase_03 | AC | 40 ms
56,020 KB |
testcase_04 | AC | 454 ms
123,620 KB |
testcase_05 | AC | 451 ms
124,944 KB |
testcase_06 | AC | 507 ms
123,884 KB |
testcase_07 | AC | 489 ms
121,248 KB |
testcase_08 | AC | 520 ms
128,624 KB |
testcase_09 | AC | 493 ms
126,416 KB |
testcase_10 | AC | 495 ms
126,792 KB |
testcase_11 | AC | 517 ms
131,376 KB |
testcase_12 | AC | 442 ms
137,176 KB |
testcase_13 | AC | 425 ms
132,976 KB |
testcase_14 | AC | 417 ms
131,708 KB |
testcase_15 | AC | 434 ms
133,116 KB |
testcase_16 | AC | 663 ms
134,700 KB |
testcase_17 | AC | 667 ms
136,340 KB |
testcase_18 | AC | 650 ms
134,492 KB |
testcase_19 | AC | 625 ms
131,700 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 748 ms
136,868 KB |
testcase_23 | AC | 767 ms
138,600 KB |
testcase_24 | AC | 702 ms
147,616 KB |
testcase_25 | AC | 735 ms
135,328 KB |
testcase_26 | AC | 689 ms
136,796 KB |
testcase_27 | AC | 656 ms
141,036 KB |
testcase_28 | AC | 680 ms
143,320 KB |
testcase_29 | AC | 656 ms
147,748 KB |
testcase_30 | AC | 724 ms
147,300 KB |
testcase_31 | AC | 710 ms
142,660 KB |
testcase_32 | AC | 688 ms
138,220 KB |
testcase_33 | AC | 737 ms
144,468 KB |
testcase_34 | AC | 723 ms
132,388 KB |
testcase_35 | AC | 732 ms
135,264 KB |
testcase_36 | WA | - |
testcase_37 | AC | 740 ms
136,848 KB |
testcase_38 | AC | 667 ms
141,660 KB |
testcase_39 | WA | - |
testcase_40 | AC | 721 ms
139,056 KB |
testcase_41 | AC | 732 ms
138,364 KB |
testcase_42 | AC | 751 ms
134,060 KB |
testcase_43 | AC | 645 ms
139,844 KB |
testcase_44 | AC | 479 ms
125,620 KB |
testcase_45 | AC | 345 ms
138,148 KB |
testcase_46 | AC | 358 ms
132,260 KB |
testcase_47 | AC | 391 ms
129,176 KB |
testcase_48 | AC | 582 ms
154,764 KB |
testcase_49 | AC | 602 ms
154,380 KB |
testcase_50 | AC | 559 ms
155,700 KB |
testcase_51 | AC | 564 ms
156,048 KB |
testcase_52 | AC | 539 ms
151,464 KB |
ソースコード
import sys r = sys.stdin N,M = map(int,r.readline().split()) G = [[] for _ in range(N+1)] rG = [[] for _ in range(N+1)] edge = [] for _ in range(M): a,b,c = map(int,r.readline().split()) G[a].append(b) rG[b].append(a) if c == 1: G[b].append(a) rG[a].append(b) edge.append((a,b,c)) order = [] memo = [0] * (N + 1) sys.setrecursionlimit(10 ** 8) """ def dfs(now): memo[now] = 1 for v in G[now]: if memo[v] == 0: dfs(v) order.append(now) for i in range(1,N+1): if memo[i] == 0: dfs(i) """ def dfs(now): stack = [now] memo[now] = 1 while stack: i = stack.pop() if memo[i] == 1: memo[i] = 2 stack.append(i) for v in G[i]: if memo[v] == 0: memo[v] = 1 stack.append(v) else: order.append(i) for i in range(1,N+1): if memo[i] == 0: dfs(i) l = [] memo = [0] * (N + 1) """ def dfs2(now,s): memo[i] = 1 s.append(i) for v in rG[now]: if memo[v] == 0: dfs2(v,s) for i in order[::-1]: if memo[i] == 0: l.append([]) dfs2(i,l[-1]) """ def dfs2(now,s): memo[now] = 1 stack = [now] while stack: i = stack.pop() s.append(i) for v in rG[i]: if memo[v] == 0: memo[v] = 1 stack.append(v) for i in order[::-1]: if memo[i] == 0: l.append([]) dfs2(i,l[-1]) parent = list(range(N+1)) def find(i): """ if parent[i] == i:return i parent[i] = find(parent[i]) return parent[i] """ l = [] while parent[i] != i: l.append(i) i = parent[i] for v in l: parent[v] = i return i def unite(i,j): I = find(i) J = find(j) if I == J:return False parent[I] = J parent[i] = J return True def isSame(i,j): return find(i) == find(j) from collections import defaultdict d = defaultdict(int) for s in l: v = s[0] for u in s: unite(v,u) for a,b,c in edge: if isSame(a,b): d[find(a)] += 1 for s in l: if len(s) <= d[find(s[0])]: print('Yes') exit() print('No')