結果
問題 | No.1023 Cyclic Tour |
ユーザー | ああいい |
提出日時 | 2022-01-27 23:10:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,142 bytes |
コンパイル時間 | 849 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 407,652 KB |
最終ジャッジ日時 | 2024-06-07 20:57:09 |
合計ジャッジ時間 | 39,908 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,376 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 43 ms
53,760 KB |
testcase_03 | AC | 43 ms
53,760 KB |
testcase_04 | AC | 1,233 ms
378,716 KB |
testcase_05 | AC | 996 ms
322,836 KB |
testcase_06 | AC | 566 ms
172,664 KB |
testcase_07 | AC | 718 ms
242,664 KB |
testcase_08 | AC | 481 ms
130,476 KB |
testcase_09 | AC | 491 ms
126,100 KB |
testcase_10 | AC | 466 ms
126,560 KB |
testcase_11 | AC | 528 ms
131,644 KB |
testcase_12 | AC | 520 ms
137,060 KB |
testcase_13 | AC | 396 ms
131,700 KB |
testcase_14 | AC | 394 ms
131,084 KB |
testcase_15 | AC | 414 ms
132,344 KB |
testcase_16 | AC | 859 ms
249,264 KB |
testcase_17 | AC | 644 ms
152,980 KB |
testcase_18 | AC | 975 ms
293,220 KB |
testcase_19 | AC | 641 ms
164,476 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 708 ms
136,484 KB |
testcase_23 | AC | 702 ms
138,328 KB |
testcase_24 | AC | 658 ms
148,740 KB |
testcase_25 | AC | 735 ms
170,520 KB |
testcase_26 | AC | 657 ms
156,096 KB |
testcase_27 | AC | 1,305 ms
367,224 KB |
testcase_28 | AC | 607 ms
143,704 KB |
testcase_29 | AC | 593 ms
150,828 KB |
testcase_30 | AC | 663 ms
146,156 KB |
testcase_31 | AC | 686 ms
150,080 KB |
testcase_32 | AC | 654 ms
145,524 KB |
testcase_33 | AC | 776 ms
186,584 KB |
testcase_34 | AC | 663 ms
132,276 KB |
testcase_35 | AC | 760 ms
180,580 KB |
testcase_36 | WA | - |
testcase_37 | AC | 1,112 ms
210,076 KB |
testcase_38 | AC | 1,070 ms
183,128 KB |
testcase_39 | WA | - |
testcase_40 | AC | 675 ms
139,056 KB |
testcase_41 | AC | 700 ms
138,616 KB |
testcase_42 | AC | 645 ms
134,268 KB |
testcase_43 | AC | 583 ms
138,700 KB |
testcase_44 | AC | 717 ms
242,876 KB |
testcase_45 | AC | 324 ms
137,776 KB |
testcase_46 | AC | 500 ms
196,908 KB |
testcase_47 | AC | 1,164 ms
393,376 KB |
testcase_48 | AC | 636 ms
181,916 KB |
testcase_49 | AC | 849 ms
274,596 KB |
testcase_50 | AC | 623 ms
224,696 KB |
testcase_51 | AC | 734 ms
227,468 KB |
testcase_52 | AC | 1,316 ms
407,652 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] 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')