結果
問題 | No.2910 単体ホモロジー入門 |
ユーザー | nikoro256 |
提出日時 | 2024-10-04 22:15:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,755 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 55,984 KB |
最終ジャッジ日時 | 2024-10-04 22:15:27 |
合計ジャッジ時間 | 3,306 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,996 KB |
testcase_01 | AC | 38 ms
54,796 KB |
testcase_02 | AC | 37 ms
55,168 KB |
testcase_03 | AC | 37 ms
54,056 KB |
testcase_04 | AC | 37 ms
55,476 KB |
testcase_05 | AC | 37 ms
54,600 KB |
testcase_06 | AC | 37 ms
54,288 KB |
testcase_07 | AC | 41 ms
55,496 KB |
testcase_08 | AC | 41 ms
55,836 KB |
testcase_09 | AC | 38 ms
55,412 KB |
testcase_10 | AC | 38 ms
55,676 KB |
testcase_11 | AC | 41 ms
54,616 KB |
testcase_12 | AC | 38 ms
54,072 KB |
testcase_13 | AC | 38 ms
54,672 KB |
testcase_14 | AC | 39 ms
54,556 KB |
testcase_15 | AC | 39 ms
54,736 KB |
testcase_16 | AC | 52 ms
54,400 KB |
testcase_17 | AC | 38 ms
54,104 KB |
testcase_18 | AC | 38 ms
53,920 KB |
testcase_19 | AC | 39 ms
55,488 KB |
testcase_20 | AC | 39 ms
54,872 KB |
testcase_21 | AC | 38 ms
55,672 KB |
testcase_22 | AC | 37 ms
55,740 KB |
testcase_23 | AC | 37 ms
54,868 KB |
testcase_24 | AC | 37 ms
55,112 KB |
testcase_25 | AC | 39 ms
54,388 KB |
testcase_26 | AC | 39 ms
55,132 KB |
testcase_27 | AC | 39 ms
54,008 KB |
testcase_28 | AC | 40 ms
55,428 KB |
testcase_29 | AC | 40 ms
55,860 KB |
testcase_30 | AC | 39 ms
55,244 KB |
testcase_31 | AC | 40 ms
54,696 KB |
testcase_32 | WA | - |
testcase_33 | AC | 39 ms
54,412 KB |
testcase_34 | AC | 39 ms
55,576 KB |
testcase_35 | AC | 38 ms
54,316 KB |
testcase_36 | AC | 38 ms
54,972 KB |
testcase_37 | AC | 38 ms
55,140 KB |
testcase_38 | AC | 39 ms
54,400 KB |
testcase_39 | AC | 37 ms
54,616 KB |
testcase_40 | AC | 44 ms
54,824 KB |
testcase_41 | AC | 37 ms
55,984 KB |
testcase_42 | AC | 38 ms
55,524 KB |
testcase_43 | AC | 38 ms
54,068 KB |
testcase_44 | AC | 40 ms
54,216 KB |
testcase_45 | AC | 40 ms
54,392 KB |
testcase_46 | AC | 41 ms
54,804 KB |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): way=[] while True: if self.parents[x] < 0: break else: way.append(x) x=self.parents[x] for w in way: self.parents[w]=x return x def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) N,M=map(int,input().split()) uf=UnionFind(N) edges=[] for _ in range(M): i,j=map(int,input().split()) edges.append((i,j)) V=set(list(map(int,input().split()))) for v in V: for v2 in V: uf.union(v,v2) for i,j in edges: if uf.same(i,j): if i in V and j in V: continue print('Yes') exit(0) uf.union(i,j) print('No')