結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
titia
|
| 提出日時 | 2020-01-31 21:36:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 603 ms / 2,000 ms |
| コード長 | 805 bytes |
| コンパイル時間 | 106 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 29,696 KB |
| 最終ジャッジ日時 | 2024-09-17 07:21:19 |
| 合計ジャッジ時間 | 5,237 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
n=int(input())
E=[tuple(map(int,input().split())) for i in range(n-1)]
# UnionFind
Group = [i for i in range(n)] # グループ分け
Nodes = [1]*n # 各グループのノードの数
def find(x):
while Group[x] != x:
x=Group[x]
return x
def Union(x,y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
Group[find(y)] = find(x)
D=[0]*n
for x,y in E:
Union(x,y)
D[x]+=1
D[y]+=1
if max(Nodes)==n:
print("Bob")
elif max(Nodes)==n-1 and max(D)==2 and not (1 in D):
print("Bob")
else:
print("Alice")
titia