結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー AzumabashiAzumabashi
提出日時 2020-04-27 09:59:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-05-01 04:04:02
合計ジャッジ時間 4,492 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 29 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 WA -
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 63 ms
11,008 KB
testcase_14 AC 62 ms
11,008 KB
testcase_15 AC 64 ms
11,008 KB
testcase_16 AC 62 ms
11,008 KB
testcase_17 AC 61 ms
11,008 KB
testcase_18 AC 130 ms
11,392 KB
testcase_19 WA -
testcase_20 AC 193 ms
11,904 KB
testcase_21 AC 291 ms
12,544 KB
testcase_22 AC 351 ms
13,056 KB
testcase_23 AC 374 ms
12,672 KB
testcase_24 AC 364 ms
12,672 KB
testcase_25 AC 374 ms
12,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, node):
        self.parent = [-1 for _ in range(node)]

    def find(self, target):
        if self.parent[target] < 0:
            return target
        else:
            self.parent[target] = self.find(self.parent[target])
            return self.parent[target]

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

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return
        if self.parent[root_x] > self.parent[root_y]:
            root_x, root_y = root_y, root_x
        self.parent[root_x] += self.parent[root_y]
        self.parent[root_y] = root_x

    def get_size(self, x):
        return -self.parent[self.find(x)]


def main():
    islands = int(input())
    uf = UnionFind(islands)
    for _ in range(islands - 1):
        u, v = map(int, input().split())
        uf.union(u, v)
    print("Bob" if uf.get_size(0) == islands else "Alice")


if __name__ == '__main__':
    main()

0