結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ntudantuda
提出日時 2022-10-10 19:56:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 90,732 KB
最終ジャッジ日時 2023-09-06 22:40:51
合計ジャッジ時間 5,872 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,332 KB
testcase_01 AC 73 ms
71,416 KB
testcase_02 AC 73 ms
71,480 KB
testcase_03 AC 73 ms
71,636 KB
testcase_04 AC 73 ms
71,296 KB
testcase_05 AC 74 ms
71,568 KB
testcase_06 AC 73 ms
71,360 KB
testcase_07 AC 74 ms
71,088 KB
testcase_08 AC 71 ms
71,632 KB
testcase_09 AC 72 ms
71,364 KB
testcase_10 AC 71 ms
71,448 KB
testcase_11 AC 72 ms
71,208 KB
testcase_12 AC 74 ms
71,212 KB
testcase_13 AC 150 ms
79,612 KB
testcase_14 AC 156 ms
79,592 KB
testcase_15 AC 153 ms
79,616 KB
testcase_16 AC 147 ms
79,548 KB
testcase_17 AC 160 ms
79,512 KB
testcase_18 AC 183 ms
81,956 KB
testcase_19 AC 215 ms
82,428 KB
testcase_20 AC 245 ms
84,624 KB
testcase_21 AC 285 ms
87,656 KB
testcase_22 AC 311 ms
90,616 KB
testcase_23 AC 302 ms
90,168 KB
testcase_24 AC 258 ms
90,732 KB
testcase_25 AC 289 ms
90,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
UV = [list(map(int,input().split())) for _ in range(N-1)]
P = [i for i in range(N)]

def find(x):
    if P[x] == x: return x
    else:
        P[x] = find(P[x]) #経路圧縮
        return P[x]
        # return find(P[x]) #経路圧縮なし

def same(x,y):
    return find(x) == find(y)

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if x > y: x,y = y,x
    P[y] = x

def group_count():
    for i in range(N):
        P[i] = find(i)
    return len(set(P))

for u,v in UV:
    unite(u,v)
gc = group_count()
if gc == 1:
    print("Bob")
elif gc > 2:
    print("Alice")
else:
    D = [0] * N
    for u,v in UV:
        D[u] += 1
        D[v] += 1
    if D.count(0) == 1 and D.count(2) == N - 1:
        print("Bob")
    else:
        print("Alice")
0