結果

問題 No.1805 Approaching Many Typhoon
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-11 02:33:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 76,944 KB
最終ジャッジ日時 2023-10-13 04:59:29
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,368 KB
testcase_01 AC 74 ms
71,268 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 73 ms
71,420 KB
testcase_04 AC 74 ms
71,512 KB
testcase_05 AC 73 ms
71,192 KB
testcase_06 AC 73 ms
71,072 KB
testcase_07 AC 73 ms
71,412 KB
testcase_08 AC 75 ms
71,384 KB
testcase_09 AC 76 ms
71,272 KB
testcase_10 AC 73 ms
71,500 KB
testcase_11 AC 74 ms
71,420 KB
testcase_12 AC 74 ms
71,192 KB
testcase_13 AC 73 ms
71,372 KB
testcase_14 AC 74 ms
71,412 KB
testcase_15 AC 74 ms
71,540 KB
testcase_16 AC 74 ms
71,416 KB
testcase_17 AC 75 ms
71,392 KB
testcase_18 AC 74 ms
71,280 KB
testcase_19 AC 74 ms
71,296 KB
testcase_20 AC 74 ms
71,348 KB
testcase_21 AC 72 ms
71,500 KB
testcase_22 AC 73 ms
71,316 KB
testcase_23 AC 73 ms
71,436 KB
testcase_24 AC 73 ms
71,216 KB
testcase_25 AC 73 ms
71,444 KB
testcase_26 AC 74 ms
71,220 KB
testcase_27 AC 74 ms
71,440 KB
testcase_28 AC 105 ms
76,928 KB
testcase_29 AC 97 ms
76,908 KB
testcase_30 AC 99 ms
76,672 KB
testcase_31 AC 97 ms
76,944 KB
testcase_32 AC 75 ms
71,352 KB
testcase_33 AC 74 ms
71,392 KB
testcase_34 AC 77 ms
71,316 KB
testcase_35 AC 83 ms
71,468 KB
testcase_36 AC 90 ms
75,472 KB
testcase_37 AC 73 ms
71,404 KB
testcase_38 AC 73 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [0]*n

    def Find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.Find(self.par[x])
            return self.par[x]

    def Unite(self, x, y):
        x = self.Find(x)
        y = self.Find(y)

        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x]
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def Same(self, x, y):
        return self.Find(x) == self.Find(y)

    def Size(self, x):
        return -self.par[self.Find(x)]

n, m = map(int, input().split())
s, g = map(int, input().split())
s, g = s-1, g-1
E = []
for i in range(m):
    f, t = map(int, input().split())
    f, t = f-1, t-1
    E.append((f, t))
u = int(input())
I = list(map(int, input().split()))
I = [i-1 for i in I]
I = set(I)
uf = UnionFind(n)
for f, t in E:
    if f not in I and t not in I:
        uf.Unite(f, t)
if uf.Same(s, g):
    print('Yes')
else:
    print('No')
0