結果

問題 No.1805 Approaching Many Typhoon
ユーザー ysys
提出日時 2022-03-07 00:40:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 77,060 KB
最終ジャッジ日時 2023-09-28 16:46:28
合計ジャッジ時間 6,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,264 KB
testcase_01 AC 79 ms
71,456 KB
testcase_02 AC 80 ms
71,224 KB
testcase_03 AC 78 ms
71,308 KB
testcase_04 AC 81 ms
71,212 KB
testcase_05 AC 79 ms
71,216 KB
testcase_06 AC 80 ms
71,168 KB
testcase_07 AC 80 ms
71,456 KB
testcase_08 AC 80 ms
71,296 KB
testcase_09 AC 80 ms
71,108 KB
testcase_10 AC 80 ms
71,260 KB
testcase_11 AC 81 ms
71,296 KB
testcase_12 AC 81 ms
71,464 KB
testcase_13 AC 81 ms
71,388 KB
testcase_14 AC 81 ms
71,108 KB
testcase_15 AC 80 ms
71,340 KB
testcase_16 AC 79 ms
71,464 KB
testcase_17 AC 80 ms
71,360 KB
testcase_18 AC 80 ms
71,168 KB
testcase_19 AC 81 ms
71,112 KB
testcase_20 AC 81 ms
71,288 KB
testcase_21 AC 81 ms
71,408 KB
testcase_22 AC 81 ms
71,228 KB
testcase_23 AC 79 ms
71,300 KB
testcase_24 AC 80 ms
71,216 KB
testcase_25 AC 78 ms
71,256 KB
testcase_26 AC 81 ms
71,248 KB
testcase_27 AC 80 ms
71,232 KB
testcase_28 AC 108 ms
76,844 KB
testcase_29 AC 106 ms
77,060 KB
testcase_30 AC 108 ms
76,768 KB
testcase_31 AC 108 ms
76,948 KB
testcase_32 AC 83 ms
71,232 KB
testcase_33 AC 81 ms
71,208 KB
testcase_34 AC 90 ms
75,744 KB
testcase_35 AC 94 ms
75,564 KB
testcase_36 AC 98 ms
76,128 KB
testcase_37 AC 80 ms
71,404 KB
testcase_38 AC 81 ms
71,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0