結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
paruf4
|
| 提出日時 | 2020-06-20 18:49:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 511 ms / 2,000 ms |
| コード長 | 995 bytes |
| コンパイル時間 | 102 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2024-07-03 17:31:10 |
| 合計ジャッジ時間 | 4,858 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
class UnionFind:
def __init__(self, n):
self.p = [-1]*n
# union by rank
self.r = [1]*n
def find(self, x):
if self.p[x] < 0:
return x
else:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
rx, ry = self.find(x), self.find(y)
if rx != ry:
if self.r[rx] > self.r[ry]:
rx, ry = ry, rx
if self.r[rx] == self.r[ry]:
self.r[ry] += 1
self.p[ry] += self.p[rx]
self.p[rx] = ry
def same(self, x, y):
return self.find(x) == self.find(y)
def count_member(self, x):
return -self.p[self.find(x)]
n=int(input())
uf=UnionFind(n)
edge=[0]*n
for i in range(n-1):
u,v=map(int,input().split())
uf.union(u,v)
edge[u]+=1
edge[v]+=1
c=[0]*n
for i in range(n):
c[i]=uf.count_member(i)
c=set(c)
from collections import Counter
if len(c)==1:
print("Bob")
elif len(c)>=3:
print("Alice")
else:
c=Counter(edge)
if c[2]==n-1:
print("Bob")
else:
print("Alice")
paruf4