結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 💕💖💞💕💖💞
提出日時 2020-04-01 14:54:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-09 03:59:23
合計ジャッジ時間 4,184 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,812 KB
testcase_02 AC 16 ms
7,828 KB
testcase_03 AC 16 ms
7,772 KB
testcase_04 AC 16 ms
7,744 KB
testcase_05 AC 16 ms
7,940 KB
testcase_06 AC 16 ms
7,784 KB
testcase_07 AC 16 ms
7,860 KB
testcase_08 AC 16 ms
7,868 KB
testcase_09 AC 16 ms
7,792 KB
testcase_10 AC 16 ms
7,840 KB
testcase_11 AC 16 ms
7,944 KB
testcase_12 AC 16 ms
7,976 KB
testcase_13 AC 49 ms
8,404 KB
testcase_14 AC 48 ms
8,412 KB
testcase_15 AC 49 ms
8,456 KB
testcase_16 AC 49 ms
8,544 KB
testcase_17 AC 48 ms
8,536 KB
testcase_18 AC 116 ms
8,736 KB
testcase_19 AC 119 ms
9,076 KB
testcase_20 AC 182 ms
9,552 KB
testcase_21 AC 284 ms
10,432 KB
testcase_22 AC 363 ms
10,932 KB
testcase_23 AC 385 ms
10,660 KB
testcase_24 AC 370 ms
10,704 KB
testcase_25 AC 378 ms
10,648 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)

edges = [0]*n
for i in range(n-1):
    a, b = map(int, input().split())
    uf.union(a,b)
    edges[a] += 1
    edges[b] += 1

cluster_num = sum([1 for p in uf.parents if p < 0])
if 1 in edges:
    cluster_num += 1
if cluster_num != 1:
    cluster_num -= 1
if cluster_num == 1:
    print("Bob")
else:
    print("Alice")

0