結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー roarisroaris
提出日時 2020-03-13 10:56:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,313 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 80,736 KB
最終ジャッジ日時 2023-08-13 23:37:54
合計ジャッジ時間 4,820 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
71,396 KB
testcase_01 AC 56 ms
71,400 KB
testcase_02 AC 57 ms
71,456 KB
testcase_03 AC 57 ms
71,376 KB
testcase_04 AC 61 ms
71,340 KB
testcase_05 AC 56 ms
71,292 KB
testcase_06 AC 58 ms
71,504 KB
testcase_07 AC 59 ms
71,648 KB
testcase_08 AC 59 ms
71,596 KB
testcase_09 AC 57 ms
71,456 KB
testcase_10 AC 58 ms
71,408 KB
testcase_11 AC 57 ms
71,452 KB
testcase_12 AC 58 ms
71,624 KB
testcase_13 AC 112 ms
78,012 KB
testcase_14 AC 107 ms
78,328 KB
testcase_15 AC 108 ms
78,520 KB
testcase_16 AC 104 ms
78,536 KB
testcase_17 AC 109 ms
78,632 KB
testcase_18 AC 116 ms
78,804 KB
testcase_19 AC 119 ms
79,116 KB
testcase_20 AC 125 ms
79,164 KB
testcase_21 AC 146 ms
79,624 KB
testcase_22 AC 152 ms
80,736 KB
testcase_23 AC 157 ms
80,508 KB
testcase_24 AC 151 ms
80,348 KB
testcase_25 AC 157 ms
80,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N = int(input())
uf = Unionfind(N)
d = [0]*N

for _ in range(N-1):
    u, v = map(int, input().split())
    uf.unite(u, v)
    d[u] += 1
    d[v] += 1

rs = set(uf.root(i) for i in range(N))

if len(rs)==1:
    print('Bob')
elif len(rs)==2:
    if 1 in d:
        print('Alice')
    else:
        print('Bob')
else:
    print('Alice')
0