結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
TakoKurage
|
| 提出日時 | 2020-01-31 23:25:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 294 ms / 2,000 ms |
| コード長 | 981 bytes |
| コンパイル時間 | 75 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 29,780 KB |
| 最終ジャッジ日時 | 2024-09-17 10:45:37 |
| 合計ジャッジ時間 | 3,335 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return (x != y)
def same(self, x, y):
return (self.find(x) == self.find(y))
def size(self, x):
return -self.data[self.find(x)]
N, *AB = map(int, open(0).read().split())
uf = UnionFind(N)
E = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
E[a].append(b)
E[b].append(a)
uf.union(a, b)
one = sum(1 for e in E if len(e) == 1)
C = len(set(uf.find(i) for i in range(N)))
if C == 1 or (C == 2 and one == 0):
print("Bob")
else:
print("Alice")
TakoKurage