結果
| 問題 |
No.1805 Approaching Many Typhoon
|
| ユーザー |
|
| 提出日時 | 2022-03-07 00:40:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 1,020 bytes |
| コンパイル時間 | 328 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 69,696 KB |
| 最終ジャッジ日時 | 2024-07-21 11:28:30 |
| 合計ジャッジ時間 | 3,603 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
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)
N, M = map(int, input().split())
S, G = map(int, input().split())
FT = [tuple(map(int, input().split())) for i in range(M)]
U = int(input())
I = set()
if U:
I = set(map(int, input().split()))
uf = UnionFind(N + 1)
for f, t in FT:
if f in I or t in I:
continue
uf.union(f, t)
if uf.same(S, G):
print('Yes')
else:
print('No')