結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 💕💖💞💕💖💞
提出日時 2020-04-01 14:42:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 10,344 KB
最終ジャッジ日時 2023-09-09 03:42:30
合計ジャッジ時間 4,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,872 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 AC 15 ms
7,760 KB
testcase_03 AC 15 ms
7,876 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 15 ms
7,876 KB
testcase_06 AC 16 ms
7,840 KB
testcase_07 AC 16 ms
7,760 KB
testcase_08 AC 16 ms
7,860 KB
testcase_09 AC 16 ms
7,956 KB
testcase_10 WA -
testcase_11 AC 16 ms
7,820 KB
testcase_12 AC 16 ms
7,804 KB
testcase_13 AC 47 ms
8,528 KB
testcase_14 AC 47 ms
8,380 KB
testcase_15 AC 47 ms
8,444 KB
testcase_16 AC 46 ms
8,432 KB
testcase_17 AC 48 ms
8,440 KB
testcase_18 AC 108 ms
8,464 KB
testcase_19 WA -
testcase_20 AC 168 ms
9,020 KB
testcase_21 AC 263 ms
9,788 KB
testcase_22 AC 331 ms
10,344 KB
testcase_23 AC 347 ms
9,784 KB
testcase_24 AC 335 ms
9,816 KB
testcase_25 AC 347 ms
9,856 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

n = int(input())
uf = UnionFind(n)

for i in range(n-1):
    a, b = map(int, input().split())
    uf.union(a,b)
    # print(uf.parents)
# print(uf.parents)
cluster_num = sum([1 for p in uf.parents if p < 0])
# print(cluster_num)
if cluster_num >= 2:
    print("Alice")
else:
    print("Bob")

0