結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-29 15:42:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 439 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 20,884 KB
最終ジャッジ日時 2023-08-30 14:59:22
合計ジャッジ時間 5,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,352 KB
testcase_01 AC 16 ms
8,340 KB
testcase_02 AC 15 ms
8,260 KB
testcase_03 AC 15 ms
8,204 KB
testcase_04 AC 15 ms
8,292 KB
testcase_05 AC 15 ms
8,336 KB
testcase_06 AC 16 ms
8,352 KB
testcase_07 AC 16 ms
8,328 KB
testcase_08 AC 16 ms
8,280 KB
testcase_09 AC 17 ms
8,408 KB
testcase_10 AC 16 ms
8,320 KB
testcase_11 AC 16 ms
8,388 KB
testcase_12 AC 16 ms
8,292 KB
testcase_13 AC 55 ms
9,552 KB
testcase_14 AC 54 ms
9,528 KB
testcase_15 AC 53 ms
9,564 KB
testcase_16 AC 54 ms
9,464 KB
testcase_17 AC 55 ms
9,472 KB
testcase_18 AC 135 ms
12,032 KB
testcase_19 AC 136 ms
12,124 KB
testcase_20 AC 211 ms
14,368 KB
testcase_21 AC 333 ms
17,736 KB
testcase_22 AC 438 ms
20,748 KB
testcase_23 AC 436 ms
20,840 KB
testcase_24 AC 431 ms
20,860 KB
testcase_25 AC 439 ms
20,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.n=n
        self.parent_size=[-1]*n
    def merge(self, a, b):
        x, y=self.leader(a), self.leader(b)
        if x == y: return 
        if abs(self.parent_size[x])<abs(self.parent_size[y]): x, y=y, x
        self.parent_size[x] += self.parent_size[y] 
        self.parent_size[y]=x
        return 
    def same(self, a, b):
        return self.leader(a) == self.leader(b)
    def leader(self, a):
        if self.parent_size[a]<0: return a
        self.parent_size[a]=self.leader(self.parent_size[a])
        return self.parent_size[a]
    def size(self, a):
        return abs(self.parent_size[self.leader(a)])
    def groups(self):
        result=[[] for _ in range(self.n)]
        for i in range(self.n):
            result[self.leader(i)].append(i)
        return [r for r in result if r != []]
n=int(input())
edge=[0]*n
uni=UnionFind(n)
for _ in range(n-1):
    a,b=map(int,input().split())
    uni.merge(a,b)
    edge[a]+=1
    edge[b]+=1
num=len(uni.groups())
if 1 in edge:
    num+=1
if num!=1:
    num-=1
print('Bob' if num==1 else 'Alice')
0