結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | naniwazu |
提出日時 | 2020-09-16 22:15:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 1,198 ms |
コンパイル使用メモリ | 86,796 KB |
実行使用メモリ | 78,580 KB |
最終ジャッジ日時 | 2023-09-04 04:02:59 |
合計ジャッジ時間 | 4,642 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
71,152 KB |
testcase_01 | AC | 74 ms
71,204 KB |
testcase_02 | AC | 74 ms
71,100 KB |
testcase_03 | AC | 70 ms
71,108 KB |
testcase_04 | AC | 72 ms
71,308 KB |
testcase_05 | AC | 68 ms
71,224 KB |
testcase_06 | AC | 70 ms
71,320 KB |
testcase_07 | AC | 70 ms
71,264 KB |
testcase_08 | AC | 76 ms
71,072 KB |
testcase_09 | AC | 72 ms
71,244 KB |
testcase_10 | WA | - |
testcase_11 | AC | 68 ms
71,308 KB |
testcase_12 | AC | 69 ms
71,240 KB |
testcase_13 | AC | 118 ms
77,600 KB |
testcase_14 | AC | 117 ms
77,680 KB |
testcase_15 | AC | 113 ms
77,684 KB |
testcase_16 | AC | 114 ms
77,540 KB |
testcase_17 | AC | 119 ms
77,600 KB |
testcase_18 | AC | 117 ms
77,656 KB |
testcase_19 | WA | - |
testcase_20 | AC | 131 ms
77,940 KB |
testcase_21 | AC | 143 ms
78,004 KB |
testcase_22 | AC | 151 ms
78,208 KB |
testcase_23 | AC | 159 ms
77,932 KB |
testcase_24 | AC | 148 ms
78,580 KB |
testcase_25 | AC | 155 ms
78,060 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: st = [] while self.parents[x] >= 0: st.append(x) x = self.parents[x] for y in st: self.parents[y] = x return 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()) import sys input = sys.stdin.buffer.readline N = int(input()) uf = UnionFind(N) for i in range(N-1): u,v = map(int,input().split()) uf.union(u,v) if uf.group_count() == 1: print('Bob') else: print('Alice')