結果

問題 No.1805 Approaching Many Typhoon
ユーザー H3PO4H3PO4
提出日時 2022-01-12 20:14:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,520 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-27 12:54:15
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 WA -
testcase_03 AC 27 ms
11,008 KB
testcase_04 AC 28 ms
11,008 KB
testcase_05 WA -
testcase_06 AC 26 ms
10,880 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 26 ms
10,880 KB
testcase_12 AC 26 ms
10,880 KB
testcase_13 AC 26 ms
10,880 KB
testcase_14 AC 25 ms
10,880 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 27 ms
11,008 KB
testcase_23 AC 27 ms
11,008 KB
testcase_24 AC 26 ms
10,880 KB
testcase_25 AC 25 ms
11,008 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 31 ms
11,136 KB
testcase_29 AC 31 ms
11,264 KB
testcase_30 AC 31 ms
11,136 KB
testcase_31 AC 36 ms
11,392 KB
testcase_32 AC 27 ms
11,008 KB
testcase_33 AC 26 ms
10,880 KB
testcase_34 AC 27 ms
11,008 KB
testcase_35 AC 29 ms
11,008 KB
testcase_36 WA -
testcase_37 AC 26 ms
11,008 KB
testcase_38 AC 26 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.height = [1] * n
        self.size = [1] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.height[x] < self.height[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.height[x] == self.height[y]:
                    self.height[x] += 1

    def issame(self, x, y):
        return self.find(x) == self.find(y)

    def group_size(self, x):
        return self.size[self.find(x)]

    def group_members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parent) if i == x]

    def group_count(self):
        return len(self.roots())


N, M = map(int, input().split())
S, G = (int(x) - 1 for x in input().split())
edges = [tuple(int(x) - 1 for x in input().split()) for _ in range(M)]
U = int(input())
I = set(map(int, input().split()))
uf = UnionFind(N)
for f, t in edges:
    if (f not in I) and (t not in I):
        uf.unite(f, t)
print("Yes" if uf.issame(S, G) else "No")
0