結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2020-04-15 17:41:06 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 771 ms / 2,000 ms |
| コード長 | 1,217 bytes |
| コンパイル時間 | 336 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 37,008 KB |
| 最終ジャッジ日時 | 2024-10-01 18:56:26 |
| 合計ジャッジ時間 | 6,488 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
class union_find():
def __init__(self, num):
self.parents = [-1 for i in range(n)]
def find(self, x):
if self.parents[x] < 0:
return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def group_count(self):
return len(self.roots())
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
n = int(input())
dicts = {i:[] for i in range(n)}
lists = [-1 for i in range(n)]
a = union_find(n)
for i in range(n - 1):
te, mp = map(int, input().split())
dicts[te] += [mp]
dicts[mp] += [te]
for i in range(n):
for j in dicts[i]:
if j > i:
a.union(i, j)
if a.group_count() < 2:
print('Bob')
elif a.group_count() > 2:
print('Alice')
else:
if len(list(filter(lambda x:len(x)==2, dicts.values()))) == n - 1:
print('Bob')
else:
print('Alice')