結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-16 13:17:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 947 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 81,268 KB
最終ジャッジ日時 2023-08-26 17:40:03
合計ジャッジ時間 5,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,228 KB
testcase_01 AC 63 ms
71,340 KB
testcase_02 AC 60 ms
71,352 KB
testcase_03 AC 60 ms
71,336 KB
testcase_04 AC 60 ms
71,464 KB
testcase_05 AC 61 ms
71,192 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 65 ms
71,500 KB
testcase_09 AC 69 ms
71,192 KB
testcase_10 AC 63 ms
71,324 KB
testcase_11 AC 65 ms
71,352 KB
testcase_12 AC 61 ms
71,064 KB
testcase_13 AC 126 ms
78,440 KB
testcase_14 AC 134 ms
78,408 KB
testcase_15 AC 127 ms
77,864 KB
testcase_16 AC 123 ms
78,360 KB
testcase_17 AC 128 ms
77,896 KB
testcase_18 AC 139 ms
78,148 KB
testcase_19 AC 164 ms
79,116 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 224 ms
80,708 KB
testcase_24 AC 197 ms
80,600 KB
testcase_25 AC 211 ms
79,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n = int(input())
uf = Unionfind(n)
count = [0]*n
for _ in range(n-1):
    u,v = map(int,input().split())
    uf.union(u,v)
    count[u] += 1
    count[v] += 1

if uf.size(0) == n:
    print("Bob")
    exit()

for i in range(n):
    if count[i] not in [0,2]:
        print("Alice")
        exit()
print("Bob")
0