結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | neterukun |
提出日時 | 2020-02-01 20:55:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,264 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 81,628 KB |
実行使用メモリ | 88,224 KB |
最終ジャッジ日時 | 2023-10-19 00:19:36 |
合計ジャッジ時間 | 4,215 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,436 KB |
testcase_01 | AC | 37 ms
53,436 KB |
testcase_02 | AC | 37 ms
53,436 KB |
testcase_03 | AC | 38 ms
53,436 KB |
testcase_04 | AC | 38 ms
53,436 KB |
testcase_05 | AC | 38 ms
53,436 KB |
testcase_06 | AC | 39 ms
53,436 KB |
testcase_07 | AC | 39 ms
53,436 KB |
testcase_08 | AC | 41 ms
53,436 KB |
testcase_09 | AC | 40 ms
53,436 KB |
testcase_10 | WA | - |
testcase_11 | AC | 39 ms
53,436 KB |
testcase_12 | AC | 40 ms
53,436 KB |
testcase_13 | AC | 126 ms
77,364 KB |
testcase_14 | AC | 122 ms
77,468 KB |
testcase_15 | AC | 125 ms
77,456 KB |
testcase_16 | AC | 119 ms
76,836 KB |
testcase_17 | AC | 132 ms
77,360 KB |
testcase_18 | AC | 165 ms
79,928 KB |
testcase_19 | WA | - |
testcase_20 | AC | 218 ms
82,324 KB |
testcase_21 | AC | 243 ms
84,932 KB |
testcase_22 | AC | 281 ms
88,224 KB |
testcase_23 | AC | 260 ms
87,756 KB |
testcase_24 | AC | 248 ms
87,752 KB |
testcase_25 | AC | 257 ms
87,752 KB |
ソースコード
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")