結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー | 89 |
提出日時 | 2022-02-21 13:01:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,764 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 71,976 KB |
最終ジャッジ日時 | 2024-06-29 17:29:42 |
合計ジャッジ時間 | 3,421 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,540 KB |
testcase_01 | AC | 42 ms
54,404 KB |
testcase_02 | AC | 41 ms
55,500 KB |
testcase_03 | AC | 41 ms
54,884 KB |
testcase_04 | AC | 41 ms
54,584 KB |
testcase_05 | AC | 41 ms
54,236 KB |
testcase_06 | AC | 42 ms
54,944 KB |
testcase_07 | AC | 42 ms
54,916 KB |
testcase_08 | AC | 42 ms
54,588 KB |
testcase_09 | AC | 41 ms
54,396 KB |
testcase_10 | AC | 40 ms
55,220 KB |
testcase_11 | AC | 41 ms
55,144 KB |
testcase_12 | AC | 42 ms
55,624 KB |
testcase_13 | AC | 42 ms
54,884 KB |
testcase_14 | AC | 42 ms
54,260 KB |
testcase_15 | AC | 41 ms
55,456 KB |
testcase_16 | AC | 41 ms
54,180 KB |
testcase_17 | AC | 41 ms
55,040 KB |
testcase_18 | AC | 41 ms
54,248 KB |
testcase_19 | AC | 42 ms
54,884 KB |
testcase_20 | AC | 41 ms
54,888 KB |
testcase_21 | AC | 41 ms
54,380 KB |
testcase_22 | AC | 41 ms
54,328 KB |
testcase_23 | AC | 41 ms
55,272 KB |
testcase_24 | AC | 41 ms
55,060 KB |
testcase_25 | AC | 40 ms
54,484 KB |
testcase_26 | AC | 41 ms
54,884 KB |
testcase_27 | AC | 40 ms
55,400 KB |
testcase_28 | AC | 67 ms
71,976 KB |
testcase_29 | AC | 67 ms
70,124 KB |
testcase_30 | AC | 67 ms
71,204 KB |
testcase_31 | AC | 67 ms
70,864 KB |
testcase_32 | AC | 42 ms
55,580 KB |
testcase_33 | AC | 43 ms
55,424 KB |
testcase_34 | AC | 45 ms
56,484 KB |
testcase_35 | AC | 49 ms
57,764 KB |
testcase_36 | AC | 55 ms
65,128 KB |
testcase_37 | AC | 40 ms
55,492 KB |
testcase_38 | AC | 41 ms
54,732 KB |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[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()) s,g = map(int,input().split()) ab = [] for i in range(m): z,x = map(int,input().split()) ab.append([z,x]) u = int(input()) p = set(list(map(int,input().split()))) q = [] for i in range(m): if (ab[i][0] not in p) and (ab[i][1] not in p): q.append(ab[i]) P = UnionFind(n) for i in range(len(q)): P.union(q[i][0]-1,q[i][1] - 1) #print(s - 1,g - 1) if P.same(s - 1,g - 1): print("Yes") else: print("No") #print(P)