結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2020-02-01 20:55:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,264 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 88,724 KB |
最終ジャッジ日時 | 2024-09-18 20:17:53 |
合計ジャッジ時間 | 3,855 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 2 |
ソースコード
class UnionFind: def __init__(self, n): self.parent = [-1] * n self.cnt = n def root(self, x): """頂点xの根を求める""" if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) return self.parent[x] def merge(self, x, y): """頂点xを含む集合と頂点y含む集合を結合する""" x = self.root(x) y = self.root(y) if x != y: if self.parent[x] > self.parent[y]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x self.cnt -= 1 def is_same(self, x, y): """頂点xと頂点yが同じ集合に属するかどうかを返す""" return self.root(x) == self.root(y) def get_size(self, x): """頂点xを含む集合の要素数を返す""" return -self.parent[self.root(x)] def get_cnt(self): """木の個数を返す""" return self.cnt n = int(input()) info = [list(map(int, input().split())) for i in range(n - 1)] uf = UnionFind(n) for i in range(n - 1): a, b = info[i] uf.merge(a, b) if uf.get_cnt() == 1: print("Bob") else: print("Alice")