結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー Kodai
提出日時 2020-04-15 17:12:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-10-01 18:54:48
合計ジャッジ時間 4,953 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import sys

sys.setrecursionlimit(10**6)

N = int(input())


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


uni = UnionFind(N)
temp_list = [0 for i in range(N)]
for i in range(N-1):
    a, b = list(map(int, input().split()))
    uni.union(a, b)
    temp_list[a] += 1
    temp_list[b] += 1



count = [i for i, x in enumerate(uni.parents) if x < 0]
count2 = Counter(temp_list)
if len(count) == 1:
    print("Bob")
elif len(count) == 2:
    if len(count2) == 2 and 2 in count2 and 0 in count2:
        if count2[2] == N-1 and count2[0] == 1:
            print("Bob")
        else:
            print("Alice")
    else:
        print("Alice")
else:
    print("Alice")
0