結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー |
![]() |
提出日時 | 2022-03-11 02:33:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,213 bytes |
コンパイル時間 | 568 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 68,736 KB |
最終ジャッジ日時 | 2024-09-15 02:28:00 |
合計ジャッジ時間 | 3,768 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
class UnionFind:def __init__(self, n):self.par = [-1]*nself.rank = [0]*ndef Find(self, x):if self.par[x] < 0:return xelse:self.par[x] = self.Find(self.par[x])return self.par[x]def Unite(self, x, y):x = self.Find(x)y = self.Find(y)if x != y:if self.rank[x] < self.rank[y]:self.par[y] += self.par[x]self.par[x] = yelse:self.par[x] += self.par[y]self.par[y] = xif self.rank[x] == self.rank[y]:self.rank[x] += 1def Same(self, x, y):return self.Find(x) == self.Find(y)def Size(self, x):return -self.par[self.Find(x)]n, m = map(int, input().split())s, g = map(int, input().split())s, g = s-1, g-1E = []for i in range(m):f, t = map(int, input().split())f, t = f-1, t-1E.append((f, t))u = int(input())I = list(map(int, input().split()))I = [i-1 for i in I]I = set(I)uf = UnionFind(n)for f, t in E:if f not in I and t not in I:uf.Unite(f, t)if uf.Same(s, g):print('Yes')else:print('No')