結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,184 KB
testcase_01 AC 29 ms
10,184 KB
testcase_02 AC 30 ms
10,184 KB
testcase_03 AC 30 ms
10,184 KB
testcase_04 AC 30 ms
10,184 KB
testcase_05 AC 29 ms
10,184 KB
testcase_06 AC 29 ms
10,184 KB
testcase_07 AC 30 ms
10,188 KB
testcase_08 AC 29 ms
10,188 KB
testcase_09 AC 30 ms
10,188 KB
testcase_10 WA -
testcase_11 AC 31 ms
10,188 KB
testcase_12 AC 30 ms
10,188 KB
testcase_13 AC 69 ms
11,860 KB
testcase_14 AC 68 ms
11,860 KB
testcase_15 AC 67 ms
11,860 KB
testcase_16 AC 69 ms
11,860 KB
testcase_17 AC 70 ms
11,856 KB
testcase_18 AC 150 ms
15,540 KB
testcase_19 WA -
testcase_20 AC 237 ms
18,768 KB
testcase_21 AC 363 ms
23,648 KB
testcase_22 AC 462 ms
27,252 KB
testcase_23 AC 482 ms
28,140 KB
testcase_24 AC 457 ms
28,140 KB
testcase_25 AC 481 ms
28,140 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)

for x,y in E:
    Union(x,y)

if max(Nodes)==n:
    print("Bob")
elif max(Nodes)==n-1 and n==3:
    print("Bob")
else:
    print("Alice")
0