結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-31 03:35:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 91,992 KB
最終ジャッジ日時 2023-09-05 19:14:49
合計ジャッジ時間 6,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,244 KB
testcase_01 AC 73 ms
71,008 KB
testcase_02 AC 73 ms
71,284 KB
testcase_03 AC 74 ms
70,964 KB
testcase_04 AC 75 ms
71,240 KB
testcase_05 AC 74 ms
71,092 KB
testcase_06 AC 74 ms
71,384 KB
testcase_07 AC 74 ms
71,264 KB
testcase_08 AC 74 ms
71,196 KB
testcase_09 AC 75 ms
71,328 KB
testcase_10 AC 74 ms
71,264 KB
testcase_11 AC 74 ms
71,240 KB
testcase_12 AC 74 ms
71,276 KB
testcase_13 AC 147 ms
78,872 KB
testcase_14 AC 143 ms
78,916 KB
testcase_15 AC 139 ms
78,604 KB
testcase_16 AC 142 ms
78,844 KB
testcase_17 AC 146 ms
79,104 KB
testcase_18 AC 177 ms
81,000 KB
testcase_19 AC 218 ms
81,876 KB
testcase_20 AC 249 ms
84,836 KB
testcase_21 AC 299 ms
88,040 KB
testcase_22 AC 349 ms
90,940 KB
testcase_23 AC 353 ms
91,992 KB
testcase_24 AC 289 ms
91,032 KB
testcase_25 AC 352 ms
91,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)

  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

def Same(x, y, par):
  return Find(x, par) == Find(y, par)

def Size(x, par):
  return -par[Find(x, par)]

n = int(input())
g = [[] for _ in range(n)]

par = [-1]* n
rank = [0]*n

for i in range(n-1):
    u, v = map(int, input().split())
    g[u].append(v)
    g[v].append(u)
    Unite(u, v, par, rank)

s = 0
for i in range(n):
    if par[i] < 0:
        s += 1
if s == 1:
    print('Bob')
elif s >= 3:
    print('Alice')
else:
    for i in range(n):
        if len(g[i]) != 0 and len(g[i]) != 2:
            print('Alice')
            exit()
    else:
        print('Bob')
0