結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2024-10-01 23:19:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 301 ms / 2,000 ms |
| コード長 | 948 bytes |
| コンパイル時間 | 323 ms |
| コンパイル使用メモリ | 82,160 KB |
| 実行使用メモリ | 80,908 KB |
| 最終ジャッジ日時 | 2024-10-01 23:19:16 |
| 合計ジャッジ時間 | 4,700 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
class UnionFind:
def __init__(self, n=1):
self.parent = [i for i in range(n)]
self.rank = [0] * n
def find(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
if self.rank[x] < self.rank[y]:
x, y = y, x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
self.parent[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
N = int(input())
uf = UnionFind(N)
D = [0] * N
for _ in range(N-1):
u, v = map(int, input().split())
uf.union(u, v)
D[u] += 1
D[v] += 1
g = [uf.find(i) for i in range(N)]
if len(set(g)) > 2 or (len(set(g)) == 2 and 1 in D):
print('Alice')
else:
print('Bob')