結果
| 問題 |
No.1805 Approaching Many Typhoon
|
| ユーザー |
ygd.
|
| 提出日時 | 2022-01-12 21:53:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,059 bytes |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-11-15 15:06:24 |
| 合計ジャッジ時間 | 2,586 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 15 |
ソースコード
import sys
#input = sys.stdin.readline #文字列につけてはダメ
#input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#MOD = pow(10,9) + 7
#MOD = 998244353
class UnionFind(object):
def __init__(self, n=1):
self.par = [i for i in range(n)]
self.rank = [0 for _ in range(n)]
self.size = [1 for _ in range(n)]
def find(self, x):
"""
x が属するグループを探索して親を出す。
"""
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
"""
x と y のグループを結合
"""
x = self.find(x)
y = self.find(y)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
"""
x と y が同じグループか否か
"""
return self.find(x) == self.find(y)
def get_size(self, x):
"""
x が属するグループの要素数
"""
x = self.find(x)
return self.size[x]
def main():
N,M = map(int,input().split())
start,goal = map(int,input().split())
start -= 1; goal -= 1
Z = []
for i in range(M):
a,b = map(int,input().split())
a -= 1; b -= 1
Z.append((a,b))
U = int(input())
S = set(map(int,input().split()))
uf = UnionFind(N)
for a,b in Z:
if a in S or b in S: continue
uf.union(a,b)
if uf.is_same(start,goal):
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
ygd.