結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
ntuda
|
| 提出日時 | 2022-10-10 19:56:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 270 ms / 2,000 ms |
| コード長 | 795 bytes |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 89,160 KB |
| 最終ジャッジ日時 | 2024-06-24 16:54:55 |
| 合計ジャッジ時間 | 4,801 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
N = int(input())
UV = [list(map(int,input().split())) for _ in range(N-1)]
P = [i for i in range(N)]
def find(x):
if P[x] == x: return x
else:
P[x] = find(P[x]) #経路圧縮
return P[x]
# return find(P[x]) #経路圧縮なし
def same(x,y):
return find(x) == find(y)
def unite(x,y):
x = find(x)
y = find(y)
if x == y: return 0
if x > y: x,y = y,x
P[y] = x
def group_count():
for i in range(N):
P[i] = find(i)
return len(set(P))
for u,v in UV:
unite(u,v)
gc = group_count()
if gc == 1:
print("Bob")
elif gc > 2:
print("Alice")
else:
D = [0] * N
for u,v in UV:
D[u] += 1
D[v] += 1
if D.count(0) == 1 and D.count(2) == N - 1:
print("Bob")
else:
print("Alice")
ntuda