結果
問題 | No.1023 Cyclic Tour |
ユーザー | ptotq |
提出日時 | 2020-04-10 22:47:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,747 bytes |
コンパイル時間 | 600 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 106,544 KB |
最終ジャッジ日時 | 2024-09-15 22:56:55 |
合計ジャッジ時間 | 14,441 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,352 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | AC | 39 ms
51,840 KB |
testcase_03 | AC | 39 ms
51,968 KB |
testcase_04 | AC | 180 ms
76,800 KB |
testcase_05 | AC | 183 ms
76,928 KB |
testcase_06 | AC | 181 ms
76,960 KB |
testcase_07 | AC | 185 ms
77,312 KB |
testcase_08 | AC | 175 ms
91,228 KB |
testcase_09 | AC | 198 ms
92,388 KB |
testcase_10 | AC | 191 ms
93,284 KB |
testcase_11 | WA | - |
testcase_12 | AC | 230 ms
101,724 KB |
testcase_13 | AC | 219 ms
103,712 KB |
testcase_14 | AC | 190 ms
104,212 KB |
testcase_15 | AC | 220 ms
102,644 KB |
testcase_16 | AC | 232 ms
103,488 KB |
testcase_17 | AC | 234 ms
102,332 KB |
testcase_18 | AC | 222 ms
99,708 KB |
testcase_19 | AC | 232 ms
102,140 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 283 ms
92,436 KB |
testcase_26 | AC | 283 ms
91,228 KB |
testcase_27 | AC | 278 ms
90,960 KB |
testcase_28 | AC | 235 ms
96,580 KB |
testcase_29 | AC | 238 ms
99,028 KB |
testcase_30 | AC | 239 ms
94,936 KB |
testcase_31 | AC | 245 ms
95,408 KB |
testcase_32 | AC | 230 ms
94,524 KB |
testcase_33 | AC | 245 ms
95,692 KB |
testcase_34 | AC | 108 ms
78,508 KB |
testcase_35 | AC | 189 ms
81,664 KB |
testcase_36 | WA | - |
testcase_37 | AC | 282 ms
100,944 KB |
testcase_38 | AC | 235 ms
99,272 KB |
testcase_39 | WA | - |
testcase_40 | AC | 270 ms
99,964 KB |
testcase_41 | AC | 270 ms
100,440 KB |
testcase_42 | AC | 280 ms
91,124 KB |
testcase_43 | AC | 207 ms
99,400 KB |
testcase_44 | AC | 186 ms
79,488 KB |
testcase_45 | AC | 196 ms
106,544 KB |
testcase_46 | AC | 190 ms
106,544 KB |
testcase_47 | AC | 107 ms
81,152 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 170 ms
90,804 KB |
testcase_51 | AC | 143 ms
83,388 KB |
testcase_52 | AC | 153 ms
83,380 KB |
ソースコード
import sys input = sys.stdin.readline class UnionFind(object): def __init__(self, n: int): self.nodes = [-1]*n def find(self, x: int) -> int: if self.nodes[x] < 0: return x else: self.nodes[x] = self.find(self.nodes[x]) return self.nodes[x] def unite(self, x: int, y: int) -> bool: root_x, root_y, nodes = self.find(x), self.find(y), self.nodes if root_x != root_y: if nodes[root_x] > nodes[root_y]: root_x, root_y = root_y, root_x nodes[root_x] += nodes[root_y] nodes[root_y] = root_x return root_x != root_y if __name__ == '__main__': N, M = map(int, input().split()) edges = [] uf = UnionFind(N) for u, v, c in (map(int, input().split()) for _ in range(M)): u -= 1 v -= 1 if c == 1: if not uf.unite(u, v): print('Yes') exit() else: edges.append((u, v)) adj = [set() for _ in range(N)] rev = [set() for _ in range(N)] for u, v in edges: par_u, par_v = uf.find(u), uf.find(v) if par_u == par_v: print('Yes') exit() adj[par_u].add(par_v) visited = [-1]*N for i in range(N): if visited[i] != -1: continue visited[i] = i stack = [i] while stack: v = stack.pop() for dest in adj[v]: if visited[dest] == i: print('Yes') exit() if visited[dest] != -1: continue visited[dest] = i stack.append(dest) else: print('No')