結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
paruf4
|
| 提出日時 | 2020-06-20 08:51:32 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 971 bytes |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 16,256 KB |
| 最終ジャッジ日時 | 2024-07-03 16:50:26 |
| 合計ジャッジ時間 | 5,571 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
ソースコード
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)
for i in range(n-1):
u,v=map(int,input().split())
if not uf.same(u,v):
uf.union(u,v)
c=[0]*n
for i in range(n):
c[i]=uf.count_member(i)
for cc in c:
if cc!=n:
print("Alice")
exit(0)
print("Bob")
paruf4