結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | uni_python |
提出日時 | 2020-08-13 23:09:21 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 2,572 bytes |
コンパイル時間 | 844 ms |
コンパイル使用メモリ | 87,084 KB |
実行使用メモリ | 81,064 KB |
最終ジャッジ日時 | 2023-07-31 00:49:47 |
合計ジャッジ時間 | 5,839 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
71,348 KB |
testcase_01 | AC | 73 ms
71,288 KB |
testcase_02 | AC | 72 ms
71,440 KB |
testcase_03 | AC | 71 ms
71,328 KB |
testcase_04 | AC | 71 ms
71,252 KB |
testcase_05 | AC | 72 ms
71,332 KB |
testcase_06 | AC | 73 ms
71,376 KB |
testcase_07 | AC | 72 ms
71,384 KB |
testcase_08 | AC | 74 ms
71,380 KB |
testcase_09 | AC | 72 ms
71,460 KB |
testcase_10 | AC | 74 ms
71,408 KB |
testcase_11 | AC | 75 ms
71,376 KB |
testcase_12 | AC | 73 ms
71,424 KB |
testcase_13 | AC | 129 ms
77,764 KB |
testcase_14 | AC | 138 ms
77,836 KB |
testcase_15 | AC | 137 ms
78,320 KB |
testcase_16 | AC | 131 ms
78,148 KB |
testcase_17 | AC | 136 ms
77,852 KB |
testcase_18 | AC | 153 ms
78,792 KB |
testcase_19 | AC | 178 ms
79,084 KB |
testcase_20 | AC | 200 ms
79,156 KB |
testcase_21 | AC | 226 ms
79,752 KB |
testcase_22 | AC | 247 ms
81,064 KB |
testcase_23 | AC | 223 ms
80,240 KB |
testcase_24 | AC | 203 ms
79,444 KB |
testcase_25 | AC | 224 ms
80,916 KB |
ソースコード
import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): ################ class UnionFind(): """ parents : 親要素(findしない場合は根ではないことの注意),根の場合は"-(要素数)" find(x):要素xの属するグループの根を返す size(x):要素xの属するグループの要素数を返す same(x,y):x,yが同じグループに属しているか返す 重いかも! members(x):要素xが属するグループに属する要素をリストで返す roots:全ての根の要素を返す group_count():グループの数を返す 重いかも! all_group_members():{根要素:[そのグループに含まれる要素のリスト]}の辞書を返す """ 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()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) ################ N=I() uf=UnionFind(N) D=[0]*N for i in range(N-1): u,v=MI() uf.union(u,v) D[u]+=1 D[v]+=1 g=uf.group_count() if g==1: print("Bob") elif g>=3: print("Alice") else: if 1 in D: print("Alice") else: print("Bob") main()