結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,184 KB
testcase_01 AC 29 ms
10,184 KB
testcase_02 AC 29 ms
10,184 KB
testcase_03 AC 29 ms
10,184 KB
testcase_04 AC 29 ms
10,184 KB
testcase_05 AC 29 ms
10,184 KB
testcase_06 AC 30 ms
10,184 KB
testcase_07 AC 30 ms
10,188 KB
testcase_08 AC 30 ms
10,188 KB
testcase_09 AC 30 ms
10,188 KB
testcase_10 WA -
testcase_11 AC 30 ms
10,188 KB
testcase_12 AC 30 ms
10,188 KB
testcase_13 AC 69 ms
11,852 KB
testcase_14 AC 68 ms
11,852 KB
testcase_15 AC 69 ms
11,852 KB
testcase_16 AC 69 ms
11,852 KB
testcase_17 AC 68 ms
11,856 KB
testcase_18 AC 155 ms
15,536 KB
testcase_19 WA -
testcase_20 AC 236 ms
18,952 KB
testcase_21 AC 355 ms
23,568 KB
testcase_22 AC 454 ms
27,248 KB
testcase_23 AC 477 ms
28,168 KB
testcase_24 AC 452 ms
28,168 KB
testcase_25 AC 486 ms
28,168 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")
else:
    print("Alice")
0