結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ああいいああいい
提出日時 2022-04-20 12:16:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 716 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 81,372 KB
最終ジャッジ日時 2023-09-02 06:11:56
合計ジャッジ時間 6,266 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,984 KB
testcase_01 AC 72 ms
71,180 KB
testcase_02 AC 70 ms
71,216 KB
testcase_03 AC 70 ms
71,168 KB
testcase_04 AC 72 ms
71,276 KB
testcase_05 AC 71 ms
71,312 KB
testcase_06 AC 70 ms
71,536 KB
testcase_07 AC 72 ms
71,320 KB
testcase_08 AC 73 ms
71,516 KB
testcase_09 AC 74 ms
71,368 KB
testcase_10 AC 74 ms
71,472 KB
testcase_11 AC 73 ms
71,260 KB
testcase_12 AC 72 ms
71,276 KB
testcase_13 AC 166 ms
78,664 KB
testcase_14 AC 162 ms
78,676 KB
testcase_15 AC 156 ms
78,784 KB
testcase_16 AC 165 ms
79,108 KB
testcase_17 AC 147 ms
78,332 KB
testcase_18 AC 201 ms
79,104 KB
testcase_19 AC 175 ms
78,980 KB
testcase_20 AC 182 ms
79,172 KB
testcase_21 AC 213 ms
79,812 KB
testcase_22 AC 228 ms
80,848 KB
testcase_23 AC 314 ms
81,196 KB
testcase_24 AC 258 ms
81,372 KB
testcase_25 AC 312 ms
81,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

parent = list(range(N))
import sys
sys.setrecursionlimit(10 ** 8)
def find(i):
    if parent[i] == i:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[I] = J
    parent[i] = J
    return True
Gnum = [0] * N
for _ in range(N-1):
    u,v = map(int,input().split())
    Gnum[u] += 1
    Gnum[v] += 1
    unite(u,v)
s = set()
for i in range(N):
    s.add(find(i))
if len(s) == 1:
    print("Bob")
elif len(s) >= 3:
    print("Alice")
else:
    flag = False
    for i in Gnum:
        if i == 1:
            flag = True
            break
    if flag:
        print('Alice')
    else:
        print('Bob')
0