結果
問題 | No.1023 Cyclic Tour |
ユーザー | ああいい |
提出日時 | 2022-01-28 00:10:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,291 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 155,912 KB |
最終ジャッジ日時 | 2024-06-07 22:46:20 |
合計ジャッジ時間 | 29,850 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,760 KB |
testcase_01 | AC | 38 ms
53,888 KB |
testcase_02 | AC | 38 ms
53,760 KB |
testcase_03 | AC | 38 ms
53,760 KB |
testcase_04 | AC | 412 ms
123,496 KB |
testcase_05 | AC | 379 ms
124,564 KB |
testcase_06 | AC | 404 ms
123,880 KB |
testcase_07 | AC | 391 ms
121,120 KB |
testcase_08 | AC | 438 ms
128,048 KB |
testcase_09 | AC | 417 ms
126,036 KB |
testcase_10 | AC | 430 ms
126,560 KB |
testcase_11 | AC | 447 ms
131,380 KB |
testcase_12 | AC | 378 ms
136,676 KB |
testcase_13 | AC | 363 ms
132,852 KB |
testcase_14 | AC | 361 ms
130,948 KB |
testcase_15 | AC | 383 ms
133,232 KB |
testcase_16 | AC | 553 ms
134,316 KB |
testcase_17 | AC | 565 ms
136,212 KB |
testcase_18 | AC | 545 ms
134,496 KB |
testcase_19 | AC | 533 ms
131,440 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 627 ms
136,468 KB |
testcase_23 | AC | 629 ms
137,948 KB |
testcase_24 | AC | 614 ms
147,364 KB |
testcase_25 | AC | 582 ms
135,220 KB |
testcase_26 | AC | 548 ms
136,248 KB |
testcase_27 | AC | 537 ms
140,528 KB |
testcase_28 | AC | 565 ms
143,444 KB |
testcase_29 | AC | 540 ms
147,372 KB |
testcase_30 | AC | 673 ms
146,796 KB |
testcase_31 | AC | 673 ms
142,020 KB |
testcase_32 | AC | 577 ms
138,080 KB |
testcase_33 | AC | 605 ms
144,048 KB |
testcase_34 | AC | 586 ms
132,280 KB |
testcase_35 | AC | 592 ms
134,760 KB |
testcase_36 | WA | - |
testcase_37 | AC | 607 ms
136,336 KB |
testcase_38 | AC | 545 ms
141,400 KB |
testcase_39 | WA | - |
testcase_40 | AC | 618 ms
138,796 KB |
testcase_41 | AC | 590 ms
137,980 KB |
testcase_42 | AC | 578 ms
133,804 KB |
testcase_43 | AC | 534 ms
139,848 KB |
testcase_44 | AC | 388 ms
125,624 KB |
testcase_45 | AC | 295 ms
138,156 KB |
testcase_46 | AC | 298 ms
131,620 KB |
testcase_47 | AC | 320 ms
129,052 KB |
testcase_48 | AC | 477 ms
154,372 KB |
testcase_49 | AC | 497 ms
153,880 KB |
testcase_50 | AC | 460 ms
155,320 KB |
testcase_51 | AC | 508 ms
155,912 KB |
testcase_52 | AC | 478 ms
151,004 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] """ ll = [] while parent[i] != i: ll.append(i) i = parent[i] for v in ll: 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')