結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2024-06-20 15:48:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 247 ms / 2,000 ms |
| コード長 | 893 bytes |
| コンパイル時間 | 367 ms |
| コンパイル使用メモリ | 82,008 KB |
| 実行使用メモリ | 90,212 KB |
| 最終ジャッジ日時 | 2024-06-20 15:48:13 |
| 合計ジャッジ時間 | 4,871 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from collections import defaultdict as dd
from sys import exit
n = int(input())
bridge = [list(map(int, input().split()))for _ in range(n-1)]
parent = [-1]*n
cnt = [0]*n
def find(x):
if parent[x] < 0: return x
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
px, py = find(x), find(y)
if px==py: return
if parent[px] > parent[py]: px, py = py, px
parent[px] += parent[py]
parent[py] = px
for x, y in bridge:
union(x, y)
cnt[x] += 1
cnt[y] += 1
dic = dd(lambda: 0)
for i in range(n):
dic[find(i)] += 1
if len(dic)==1:
print("Bob")
elif len(dic)==2:
x, y = dic.keys()
if dic[x] > dic[y]: x, y = y, x
if dic[x]==1:
for i in range(n):
if not(i==x or cnt[i]==2):
print("Alice")
exit()
print("Bob")
else:
print("Alice")
else:
print("Alice")