結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | neterukun |
提出日時 | 2020-02-01 21:08:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,792 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 81,764 KB |
実行使用メモリ | 99,252 KB |
最終ジャッジ日時 | 2023-10-19 00:21:12 |
合計ジャッジ時間 | 4,563 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,580 KB |
testcase_01 | AC | 40 ms
53,580 KB |
testcase_02 | AC | 40 ms
53,580 KB |
testcase_03 | AC | 40 ms
53,580 KB |
testcase_04 | AC | 40 ms
53,580 KB |
testcase_05 | AC | 40 ms
53,580 KB |
testcase_06 | AC | 40 ms
53,580 KB |
testcase_07 | AC | 41 ms
53,580 KB |
testcase_08 | AC | 41 ms
53,580 KB |
testcase_09 | AC | 41 ms
53,580 KB |
testcase_10 | WA | - |
testcase_11 | AC | 40 ms
53,580 KB |
testcase_12 | AC | 41 ms
53,580 KB |
testcase_13 | AC | 135 ms
78,668 KB |
testcase_14 | AC | 135 ms
78,732 KB |
testcase_15 | AC | 137 ms
78,668 KB |
testcase_16 | AC | 135 ms
78,668 KB |
testcase_17 | AC | 148 ms
78,772 KB |
testcase_18 | AC | 177 ms
83,188 KB |
testcase_19 | WA | - |
testcase_20 | AC | 243 ms
87,748 KB |
testcase_21 | AC | 286 ms
94,040 KB |
testcase_22 | AC | 331 ms
98,236 KB |
testcase_23 | AC | 313 ms
99,252 KB |
testcase_24 | AC | 283 ms
99,252 KB |
testcase_25 | AC | 310 ms
99,252 KB |
ソースコード
class UnionFind: def __init__(self, n): self.parent = [-1] * n self.cnt = n self.n = 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 def members(self, x): """頂点xが属する集合の要素を列挙する 計算量に注意""" root_x = self.root(x) return [i for i in range(self.n) if self.root(i) == root_x] n = int(input()) info = [list(map(int, input().split())) for i in range(n - 1)] tree = [[] for i in range(n)] for i in range(n - 1): a, b = info[i] tree[a].append(b) tree[b].append(a) uf = UnionFind(n) for i in range(n - 1): a, b = info[i] uf.merge(a, b) if uf.get_cnt() == 1: print("Bob") elif uf.get_cnt() == 2: for i in range(n): if len(tree[i]) != 2 or len(tree[i]) != 0: print("Alice") break else: print("Bob") else: print("Alice")