結果
| 問題 | No.1805 Approaching Many Typhoon |
| ユーザー |
titia
|
| 提出日時 | 2026-01-31 01:49:28 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 914 bytes |
| 記録 | |
| コンパイル時間 | 240 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 65,348 KB |
| 最終ジャッジ日時 | 2026-01-31 01:49:32 |
| 合計ジャッジ時間 | 4,235 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
S0,G0=list(map(int,input().split()))
E=[list(map(int,input().split())) for i in range(M)]
U=int(input())
S=set(map(int,input().split()))
# UnionFind
Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
Group[find(y)] = find(x)
for x,y in E:
if x in S:
continue
if y in S:
continue
Union(x,y)
if find(S0)==find(G0):
print("Yes")
else:
print("No")
titia