結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | O2MT |
提出日時 | 2020-12-04 18:12:17 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 457 ms / 2,000 ms |
コード長 | 1,604 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 11,120 KB |
実行使用メモリ | 11,736 KB |
最終ジャッジ日時 | 2023-10-13 07:44:53 |
合計ジャッジ時間 | 4,881 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
8,816 KB |
testcase_01 | AC | 19 ms
8,676 KB |
testcase_02 | AC | 19 ms
8,812 KB |
testcase_03 | AC | 19 ms
8,744 KB |
testcase_04 | AC | 19 ms
8,608 KB |
testcase_05 | AC | 20 ms
8,688 KB |
testcase_06 | AC | 20 ms
8,660 KB |
testcase_07 | AC | 19 ms
8,676 KB |
testcase_08 | AC | 19 ms
8,644 KB |
testcase_09 | AC | 21 ms
8,796 KB |
testcase_10 | AC | 20 ms
8,804 KB |
testcase_11 | AC | 20 ms
8,708 KB |
testcase_12 | AC | 20 ms
8,836 KB |
testcase_13 | AC | 59 ms
8,880 KB |
testcase_14 | AC | 59 ms
8,972 KB |
testcase_15 | AC | 58 ms
8,960 KB |
testcase_16 | AC | 60 ms
8,844 KB |
testcase_17 | AC | 61 ms
8,904 KB |
testcase_18 | AC | 143 ms
9,496 KB |
testcase_19 | AC | 143 ms
9,504 KB |
testcase_20 | AC | 228 ms
10,076 KB |
testcase_21 | AC | 354 ms
11,032 KB |
testcase_22 | AC | 446 ms
11,736 KB |
testcase_23 | AC | 451 ms
11,196 KB |
testcase_24 | AC | 446 ms
11,272 KB |
testcase_25 | AC | 457 ms
11,136 KB |
ソースコード
from collections import defaultdict 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): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members from collections import deque N = int(input()) uf = UnionFind(N) l = [0 for _ in range(N)] for _ in range(N-1): v1,v2 = map(int,input().split()) uf.union(v1,v2) l[v1] += 1 l[v2] += 1 num = 0 for i in range(N): num = max(num,uf.size(i)) ans = "Alice" check = False if l.count(2) == N-1 and l.count(0) == 1: check = True if num == N or (num == N-1 and check): ans = "Bob" print(ans)