結果
問題 | No.1023 Cyclic Tour |
ユーザー | ああいい |
提出日時 | 2022-01-27 23:07:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,116 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 82,792 KB |
実行使用メモリ | 410,216 KB |
最終ジャッジ日時 | 2024-06-07 20:53:19 |
合計ジャッジ時間 | 41,775 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,320 KB |
testcase_01 | AC | 38 ms
55,744 KB |
testcase_02 | AC | 40 ms
54,172 KB |
testcase_03 | AC | 38 ms
55,912 KB |
testcase_04 | AC | 1,272 ms
378,992 KB |
testcase_05 | AC | 1,075 ms
328,028 KB |
testcase_06 | AC | 644 ms
175,120 KB |
testcase_07 | AC | 804 ms
245,984 KB |
testcase_08 | AC | 545 ms
131,508 KB |
testcase_09 | AC | 529 ms
126,772 KB |
testcase_10 | AC | 517 ms
127,776 KB |
testcase_11 | AC | 564 ms
132,704 KB |
testcase_12 | AC | 470 ms
137,016 KB |
testcase_13 | AC | 453 ms
132,128 KB |
testcase_14 | AC | 445 ms
131,408 KB |
testcase_15 | AC | 469 ms
134,188 KB |
testcase_16 | AC | 958 ms
253,140 KB |
testcase_17 | AC | 732 ms
154,288 KB |
testcase_18 | AC | 1,072 ms
297,476 KB |
testcase_19 | AC | 738 ms
167,468 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 792 ms
139,016 KB |
testcase_23 | AC | 832 ms
140,528 KB |
testcase_24 | AC | 740 ms
151,000 KB |
testcase_25 | AC | 840 ms
173,912 KB |
testcase_26 | AC | 771 ms
157,960 KB |
testcase_27 | AC | 1,375 ms
370,140 KB |
testcase_28 | AC | 707 ms
146,196 KB |
testcase_29 | AC | 686 ms
152,492 KB |
testcase_30 | AC | 749 ms
148,692 KB |
testcase_31 | AC | 774 ms
151,988 KB |
testcase_32 | AC | 739 ms
147,232 KB |
testcase_33 | AC | 893 ms
189,036 KB |
testcase_34 | AC | 743 ms
134,304 KB |
testcase_35 | AC | 853 ms
183,604 KB |
testcase_36 | WA | - |
testcase_37 | AC | 907 ms
214,060 KB |
testcase_38 | AC | 802 ms
184,072 KB |
testcase_39 | WA | - |
testcase_40 | AC | 733 ms
141,864 KB |
testcase_41 | AC | 772 ms
139,948 KB |
testcase_42 | AC | 730 ms
135,040 KB |
testcase_43 | AC | 657 ms
141,124 KB |
testcase_44 | AC | 749 ms
243,084 KB |
testcase_45 | AC | 368 ms
140,096 KB |
testcase_46 | AC | 555 ms
198,968 KB |
testcase_47 | AC | 1,148 ms
395,216 KB |
testcase_48 | AC | 681 ms
189,772 KB |
testcase_49 | AC | 900 ms
282,024 KB |
testcase_50 | AC | 658 ms
227,672 KB |
testcase_51 | AC | 767 ms
236,432 KB |
testcase_52 | AC | 1,304 ms
410,216 KB |
ソースコード
N,M = map(int,input().split()) G = [[] for _ in range(N+1)] rG = [[] for _ in range(N+1)] edge = [] for _ in range(M): a,b,c = map(int,input().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) import sys 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] 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')