結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー titiatitia
提出日時 2020-01-31 21:36:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,004 KB
実行使用メモリ 28,940 KB
最終ジャッジ日時 2023-10-17 08:53:38
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,204 KB
testcase_01 AC 30 ms
10,204 KB
testcase_02 AC 30 ms
10,204 KB
testcase_03 AC 29 ms
10,204 KB
testcase_04 AC 29 ms
10,204 KB
testcase_05 AC 29 ms
10,204 KB
testcase_06 AC 31 ms
10,204 KB
testcase_07 AC 30 ms
10,208 KB
testcase_08 AC 30 ms
10,208 KB
testcase_09 AC 30 ms
10,208 KB
testcase_10 AC 30 ms
10,208 KB
testcase_11 AC 30 ms
10,208 KB
testcase_12 AC 30 ms
10,208 KB
testcase_13 AC 71 ms
11,968 KB
testcase_14 AC 70 ms
11,968 KB
testcase_15 AC 71 ms
11,968 KB
testcase_16 AC 72 ms
11,968 KB
testcase_17 AC 71 ms
11,968 KB
testcase_18 AC 156 ms
15,824 KB
testcase_19 AC 166 ms
15,828 KB
testcase_20 AC 251 ms
19,316 KB
testcase_21 AC 383 ms
24,196 KB
testcase_22 AC 501 ms
28,064 KB
testcase_23 AC 515 ms
28,940 KB
testcase_24 AC 485 ms
28,940 KB
testcase_25 AC 510 ms
28,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
E=[tuple(map(int,input().split())) for i in range(n-1)]

# UnionFind

Group = [i for i in range(n)] # グループ分け
Nodes = [1]*n # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

D=[0]*n
for x,y in E:
    Union(x,y)
    D[x]+=1
    D[y]+=1

if max(Nodes)==n:
    print("Bob")
elif max(Nodes)==n-1 and max(D)==2 and not (1 in D):
    print("Bob")
else:
    print("Alice")

0