結果
問題 | No.1023 Cyclic Tour |
ユーザー | ああいい |
提出日時 | 2022-01-27 23:04:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,109 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,828 KB |
実行使用メモリ | 409,484 KB |
最終ジャッジ日時 | 2024-06-07 20:50:00 |
合計ジャッジ時間 | 45,080 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,384 KB |
testcase_01 | AC | 42 ms
55,280 KB |
testcase_02 | AC | 43 ms
56,088 KB |
testcase_03 | AC | 42 ms
55,004 KB |
testcase_04 | AC | 678 ms
194,740 KB |
testcase_05 | AC | 562 ms
145,512 KB |
testcase_06 | AC | 651 ms
150,560 KB |
testcase_07 | AC | 652 ms
158,396 KB |
testcase_08 | AC | 598 ms
120,368 KB |
testcase_09 | AC | 554 ms
118,580 KB |
testcase_10 | AC | 568 ms
118,692 KB |
testcase_11 | WA | - |
testcase_12 | AC | 514 ms
136,376 KB |
testcase_13 | AC | 506 ms
127,452 KB |
testcase_14 | AC | 475 ms
121,048 KB |
testcase_15 | AC | 522 ms
133,996 KB |
testcase_16 | AC | 1,190 ms
308,904 KB |
testcase_17 | AC | 769 ms
139,828 KB |
testcase_18 | AC | 1,146 ms
285,620 KB |
testcase_19 | AC | 1,127 ms
295,852 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 812 ms
136,096 KB |
testcase_26 | AC | 864 ms
141,456 KB |
testcase_27 | AC | 1,541 ms
375,300 KB |
testcase_28 | AC | 828 ms
139,280 KB |
testcase_29 | AC | 793 ms
139,828 KB |
testcase_30 | AC | 848 ms
140,928 KB |
testcase_31 | AC | 886 ms
153,656 KB |
testcase_32 | AC | 800 ms
136,740 KB |
testcase_33 | AC | 862 ms
139,728 KB |
testcase_34 | AC | 816 ms
133,148 KB |
testcase_35 | AC | 880 ms
145,976 KB |
testcase_36 | WA | - |
testcase_37 | AC | 902 ms
143,668 KB |
testcase_38 | AC | 785 ms
138,136 KB |
testcase_39 | WA | - |
testcase_40 | AC | 834 ms
137,536 KB |
testcase_41 | AC | 826 ms
137,124 KB |
testcase_42 | AC | 891 ms
135,932 KB |
testcase_43 | AC | 812 ms
136,788 KB |
testcase_44 | AC | 1,335 ms
388,880 KB |
testcase_45 | AC | 412 ms
139,088 KB |
testcase_46 | AC | 866 ms
304,748 KB |
testcase_47 | AC | 391 ms
130,868 KB |
testcase_48 | AC | 906 ms
244,016 KB |
testcase_49 | AC | 1,005 ms
280,824 KB |
testcase_50 | AC | 1,479 ms
409,484 KB |
testcase_51 | AC | 853 ms
227,092 KB |
testcase_52 | AC | 811 ms
229,356 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 G[i]: if memo[v] == 0: memo[v] = 1 stack.append(v) for i in order: 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')