結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
|
提出日時 | 2020-03-20 13:28:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 486 ms / 2,000 ms |
コード長 | 821 bytes |
コンパイル時間 | 106 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-12-14 04:08:45 |
合計ジャッジ時間 | 4,490 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
from collections import Counter class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] def find(self, x): if self.parent[x] == x: return x 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: return self.parent[x] = y def main(): N = int(input()) deg = [0] * N uf = UnionFind(N) for _ in range(N-1): u, v = map(int, input().split()) deg[u] += 1 deg[v] += 1 uf.union(u, v) s = set(uf.find(i) for i in range(N)) sets = len(s) dc = Counter(deg) bob = (sets == 1) or (sets == 2 and dc[0] == 1 and dc[2] == N - 1) print('Bob' if bob else 'Alice') main()