結果
| 問題 |
No.1805 Approaching Many Typhoon
|
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2022-01-15 01:38:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 82,720 KB |
| 実行使用メモリ | 68,864 KB |
| 最終ジャッジ日時 | 2024-11-20 18:32:51 |
| 合計ジャッジ時間 | 3,120 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
def uf_find(n,p):
ufl = []
while p[n] != n:
ufl.append(n)
n = p[n]
for i in ufl:
p[i] = n
return n
def uf_union(a,b,p,rank):
ap = uf_find(a,p)
bp = uf_find(b,p)
if ap == bp:
return True
else:
if rank[ap] > rank[bp]:
p[bp] = ap
elif rank[ap] < rank[bp]:
p[ap] = bp
else:
p[bp] = ap
rank[ap] += 1
return False
N,M = map(int,input().split())
S,G = map(int,input().split())
S -= 1; G -= 1
e = []
for i in range(M):
F,T = map(int,input().split())
F -= 1
T -= 1
e.append((F,T))
U = int(input())
I = [] if U == 0 else list(map(int,input().split()))
for i in range(len(I)):
I[i] -= 1
s = set(I)
p = [i for i in range(N)]
rank = [0] * N
for u,v in e:
if u not in s and v not in s:
uf_union(u,v,p,rank)
if uf_find(S,p) == uf_find(G,p):
print ("Yes")
else:
print ("No")
SPD_9X2