結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | 👑 rin204 |
提出日時 | 2022-01-18 22:41:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,611 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 78,976 KB |
最終ジャッジ日時 | 2024-05-02 19:34:49 |
合計ジャッジ時間 | 4,242 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,224 KB |
testcase_01 | AC | 40 ms
52,224 KB |
testcase_02 | AC | 43 ms
52,352 KB |
testcase_03 | WA | - |
testcase_04 | AC | 42 ms
52,096 KB |
testcase_05 | AC | 41 ms
52,352 KB |
testcase_06 | AC | 43 ms
52,608 KB |
testcase_07 | AC | 44 ms
52,864 KB |
testcase_08 | AC | 44 ms
52,864 KB |
testcase_09 | AC | 43 ms
52,736 KB |
testcase_10 | AC | 44 ms
52,736 KB |
testcase_11 | AC | 45 ms
53,120 KB |
testcase_12 | AC | 43 ms
52,608 KB |
testcase_13 | AC | 131 ms
76,928 KB |
testcase_14 | AC | 126 ms
76,928 KB |
testcase_15 | AC | 138 ms
76,544 KB |
testcase_16 | AC | 129 ms
76,672 KB |
testcase_17 | WA | - |
testcase_18 | AC | 160 ms
77,312 KB |
testcase_19 | AC | 181 ms
78,080 KB |
testcase_20 | AC | 209 ms
77,824 KB |
testcase_21 | AC | 242 ms
78,208 KB |
testcase_22 | AC | 256 ms
78,976 KB |
testcase_23 | AC | 257 ms
78,848 KB |
testcase_24 | AC | 231 ms
78,464 KB |
testcase_25 | AC | 253 ms
78,592 KB |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n self.group = 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 self.group -= 1 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 self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n = int(input()) UF = UnionFind(n) cnt = [0] * n for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 UF.union(u, v) cnt[u] += 1 cnt[v] += 1 if UF.group_count() == 1: print("Bob") elif UF.group_count() >= 3: print("Alice") elif any(c == 1 for c in cnt): print("Alice") else: print("Bob")