結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | buey_t |
提出日時 | 2023-03-27 09:40:06 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,845 bytes |
コンパイル時間 | 390 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 92,552 KB |
最終ジャッジ日時 | 2024-09-19 10:07:31 |
合計ジャッジ時間 | 6,738 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
89,216 KB |
testcase_01 | AC | 126 ms
89,088 KB |
testcase_02 | AC | 126 ms
89,344 KB |
testcase_03 | AC | 125 ms
89,088 KB |
testcase_04 | AC | 130 ms
89,472 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 130 ms
89,320 KB |
testcase_09 | RE | - |
testcase_10 | AC | 129 ms
89,472 KB |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
ソースコード
def main(): from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum from heapq import heapify, heappop, heappush from bisect import bisect_left, bisect_right from copy import deepcopy import copy import random from collections import deque,Counter,defaultdict from itertools import permutations,combinations from decimal import Decimal,ROUND_HALF_UP #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP) from functools import lru_cache, reduce #@lru_cache(maxsize=None) from operator import add,sub,mul,xor,and_,or_,itemgetter INF = 10**18 mod1 = 10**9+7 mod2 = 998244353 #DecimalならPython #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!! ''' ''' class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n #親だけ self.edge = [0]*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 self.parents[x] > self.parents[y]: x, y = y, x self.edge[x] += 1 if x == y: return self.parents[x] += self.parents[y] self.edge[x] += self.edge[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 def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) N = int(input()) uf = UnionFind(N-1) for _ in range(N-2): u,v = map(int, input().split()) uf.union(u,v) if uf.group_count() == 1: print('Bob') else: print('Alice') if __name__ == '__main__': main()