結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー convexineqconvexineq
提出日時 2020-01-31 21:40:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,429 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,044 KB
実行使用メモリ 15,508 KB
最終ジャッジ日時 2023-10-17 09:00:46
合計ジャッジ時間 3,423 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,224 KB
testcase_01 AC 30 ms
10,224 KB
testcase_02 AC 30 ms
10,224 KB
testcase_03 AC 30 ms
10,224 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 30 ms
10,224 KB
testcase_07 AC 31 ms
10,224 KB
testcase_08 AC 29 ms
10,224 KB
testcase_09 AC 30 ms
10,224 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 49 ms
10,740 KB
testcase_15 AC 49 ms
10,740 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 146 ms
12,852 KB
testcase_21 AC 219 ms
14,172 KB
testcase_22 AC 282 ms
15,228 KB
testcase_23 AC 289 ms
15,492 KB
testcase_24 WA -
testcase_25 AC 287 ms
15,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す.
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read


n = int(input())

res = [0]*n
UF = UnionFind(n)
cnt = n
for _ in range(n-1):
    a,b = [int(i) for i in readline().split()]
    res[a] += 1
    res[b] += 1
    if UF.merge(a,b): cnt -= 1

d = res.count(1)

if cnt >= 3:
    print("Alice")
elif cnt == 1:
    print("Bob")
else:
    if d == 0: 
        print("Alice")
    else:
        print("Bob")
        









0