結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | s_shohei |
提出日時 | 2020-04-11 20:51:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 81,632 KB |
実行使用メモリ | 88,464 KB |
最終ジャッジ日時 | 2023-10-19 15:00:25 |
合計ジャッジ時間 | 5,080 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,448 KB |
testcase_01 | AC | 38 ms
53,448 KB |
testcase_02 | AC | 39 ms
53,448 KB |
testcase_03 | AC | 38 ms
53,448 KB |
testcase_04 | AC | 40 ms
53,448 KB |
testcase_05 | AC | 38 ms
53,448 KB |
testcase_06 | AC | 37 ms
53,448 KB |
testcase_07 | AC | 39 ms
53,448 KB |
testcase_08 | AC | 39 ms
53,448 KB |
testcase_09 | AC | 38 ms
53,448 KB |
testcase_10 | AC | 39 ms
53,448 KB |
testcase_11 | AC | 39 ms
53,448 KB |
testcase_12 | AC | 39 ms
53,448 KB |
testcase_13 | AC | 145 ms
77,432 KB |
testcase_14 | AC | 138 ms
77,464 KB |
testcase_15 | AC | 143 ms
77,728 KB |
testcase_16 | AC | 147 ms
77,568 KB |
testcase_17 | AC | 151 ms
77,632 KB |
testcase_18 | AC | 190 ms
79,624 KB |
testcase_19 | AC | 211 ms
80,360 KB |
testcase_20 | AC | 259 ms
82,676 KB |
testcase_21 | AC | 326 ms
85,728 KB |
testcase_22 | AC | 370 ms
88,164 KB |
testcase_23 | AC | 375 ms
88,116 KB |
testcase_24 | AC | 326 ms
88,464 KB |
testcase_25 | AC | 374 ms
88,064 KB |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) n = int(input()) uf = UnionFind(n) link = [[] for _ in range(n)] for i in range(n-1): tmp = list(map(int,input().split())) link[tmp[0]].append(tmp[1]) link[tmp[1]].append(tmp[0]) uf.union(tmp[0],tmp[1]) if uf.group_count() == 1: print("Bob") exit() if uf.group_count() > 2: print("Alice") exit() for i in range(len(link)): if len(link[i])!=0 and len(link[i])!=2: print("Alice") exit() print("Bob")