結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー KodaiKodai
提出日時 2020-04-15 17:12:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-09 18:52:23
合計ジャッジ時間 4,101 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,880 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 24 ms
10,880 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 AC 26 ms
10,880 KB
testcase_05 AC 25 ms
10,880 KB
testcase_06 AC 24 ms
10,880 KB
testcase_07 AC 25 ms
10,880 KB
testcase_08 AC 24 ms
10,880 KB
testcase_09 AC 26 ms
10,880 KB
testcase_10 AC 25 ms
10,880 KB
testcase_11 AC 25 ms
10,880 KB
testcase_12 AC 26 ms
11,008 KB
testcase_13 AC 63 ms
11,264 KB
testcase_14 AC 65 ms
11,136 KB
testcase_15 AC 66 ms
11,136 KB
testcase_16 AC 64 ms
11,264 KB
testcase_17 AC 64 ms
11,264 KB
testcase_18 AC 142 ms
11,904 KB
testcase_19 AC 140 ms
11,904 KB
testcase_20 AC 207 ms
12,416 KB
testcase_21 AC 308 ms
13,312 KB
testcase_22 AC 386 ms
13,952 KB
testcase_23 AC 397 ms
13,440 KB
testcase_24 AC 398 ms
13,568 KB
testcase_25 AC 397 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

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