結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-16 13:19:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 81,436 KB
最終ジャッジ日時 2023-08-26 17:42:47
合計ジャッジ時間 4,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,312 KB
testcase_01 AC 66 ms
71,328 KB
testcase_02 AC 66 ms
71,388 KB
testcase_03 AC 66 ms
71,168 KB
testcase_04 AC 69 ms
71,508 KB
testcase_05 AC 65 ms
71,312 KB
testcase_06 AC 65 ms
71,280 KB
testcase_07 AC 75 ms
71,164 KB
testcase_08 AC 68 ms
71,204 KB
testcase_09 AC 68 ms
71,204 KB
testcase_10 AC 67 ms
71,528 KB
testcase_11 AC 68 ms
71,384 KB
testcase_12 AC 67 ms
71,308 KB
testcase_13 AC 138 ms
78,388 KB
testcase_14 AC 139 ms
78,080 KB
testcase_15 AC 138 ms
78,172 KB
testcase_16 AC 135 ms
78,088 KB
testcase_17 AC 148 ms
78,192 KB
testcase_18 AC 158 ms
78,368 KB
testcase_19 AC 198 ms
79,508 KB
testcase_20 AC 223 ms
80,088 KB
testcase_21 AC 242 ms
80,060 KB
testcase_22 AC 266 ms
81,436 KB
testcase_23 AC 235 ms
80,664 KB
testcase_24 AC 213 ms
80,776 KB
testcase_25 AC 229 ms
79,760 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()

s = 0
for i in range(n):
    if uf.find(i) == i:
        s += 1
    if count[i] not in [0,2]:
        print("Alice")
        exit()
print("Bob" if s == 2 else "Alice")
0