結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | aqua_tenhou |
提出日時 | 2020-09-15 22:11:36 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 491 ms / 2,000 ms |
コード長 | 1,569 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 10,844 KB |
実行使用メモリ | 25,596 KB |
最終ジャッジ日時 | 2023-09-04 02:58:44 |
合計ジャッジ時間 | 5,056 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,188 KB |
testcase_01 | AC | 16 ms
8,028 KB |
testcase_02 | AC | 16 ms
8,044 KB |
testcase_03 | AC | 16 ms
8,040 KB |
testcase_04 | AC | 16 ms
8,060 KB |
testcase_05 | AC | 16 ms
8,068 KB |
testcase_06 | AC | 15 ms
7,968 KB |
testcase_07 | AC | 16 ms
8,028 KB |
testcase_08 | AC | 16 ms
8,120 KB |
testcase_09 | AC | 16 ms
8,116 KB |
testcase_10 | AC | 15 ms
8,060 KB |
testcase_11 | AC | 15 ms
8,016 KB |
testcase_12 | AC | 16 ms
8,100 KB |
testcase_13 | AC | 56 ms
10,128 KB |
testcase_14 | AC | 55 ms
10,064 KB |
testcase_15 | AC | 56 ms
10,036 KB |
testcase_16 | AC | 56 ms
10,108 KB |
testcase_17 | AC | 57 ms
10,004 KB |
testcase_18 | AC | 139 ms
13,460 KB |
testcase_19 | AC | 152 ms
13,460 KB |
testcase_20 | AC | 228 ms
16,664 KB |
testcase_21 | AC | 352 ms
21,272 KB |
testcase_22 | AC | 459 ms
24,704 KB |
testcase_23 | AC | 486 ms
25,592 KB |
testcase_24 | AC | 465 ms
25,568 KB |
testcase_25 | AC | 491 ms
25,596 KB |
ソースコード
#UnionFind 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()) 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 = int(input()) uf = UnionFind(n) V = [[] for i in range(n)] for _ in range(n-1): v,w = map(int,input().split()) V[v].append(w) V[w].append(v) uf.union(v,w) if uf.group_count() == 1: print("Bob") elif uf.group_count() == 2: c = 0 for x in V: if len(x)%2 != 0: c = 1 break print(["Bob","Alice"][c]) else: print("Alice")