結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー c-yanc-yan
提出日時 2020-06-21 01:31:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 10,860 KB
最終ジャッジ日時 2023-09-16 17:57:50
合計ジャッジ時間 4,256 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,836 KB
testcase_01 AC 15 ms
7,804 KB
testcase_02 AC 17 ms
7,832 KB
testcase_03 AC 15 ms
7,776 KB
testcase_04 AC 15 ms
7,908 KB
testcase_05 AC 15 ms
7,904 KB
testcase_06 AC 15 ms
7,772 KB
testcase_07 AC 16 ms
7,816 KB
testcase_08 AC 15 ms
7,852 KB
testcase_09 AC 15 ms
7,852 KB
testcase_10 AC 16 ms
7,848 KB
testcase_11 AC 15 ms
7,808 KB
testcase_12 AC 15 ms
7,912 KB
testcase_13 AC 49 ms
8,472 KB
testcase_14 AC 49 ms
8,416 KB
testcase_15 AC 49 ms
8,480 KB
testcase_16 AC 49 ms
8,464 KB
testcase_17 AC 49 ms
8,456 KB
testcase_18 AC 116 ms
8,928 KB
testcase_19 AC 116 ms
9,060 KB
testcase_20 AC 180 ms
9,672 KB
testcase_21 AC 273 ms
10,460 KB
testcase_22 AC 354 ms
10,860 KB
testcase_23 AC 400 ms
10,844 KB
testcase_24 AC 365 ms
10,632 KB
testcase_25 AC 395 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j


setrecursionlimit(10 ** 6)

N = int(input())

parent = [-1] * N
edges = [0] * N
for _ in range(N - 1):
    u, v = map(int, input().split())
    unite(parent, u, v)
    edges[u] += 1
    edges[v] += 1

# Alice が橋を爆破する前のグループ数
groups = sum(1 for e in parent if e < 0)

# Alice が橋を1つ爆破した後のグループ数
if 1 in edges:
    groups += 1

# Bob が橋を1つ掛けた後のグループ数
if groups != 1:
    groups -= 1

if groups == 1:
    print('Bob')
else:
    print('Alice')
0