結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | buey_t |
提出日時 | 2023-03-27 09:41:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,833 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 92,416 KB |
最終ジャッジ日時 | 2024-09-19 10:07:40 |
合計ジャッジ時間 | 7,578 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 158 ms
89,216 KB |
testcase_01 | AC | 163 ms
89,344 KB |
testcase_02 | AC | 159 ms
89,344 KB |
testcase_03 | AC | 161 ms
89,216 KB |
testcase_04 | AC | 160 ms
89,216 KB |
testcase_05 | AC | 163 ms
89,216 KB |
testcase_06 | AC | 160 ms
89,472 KB |
testcase_07 | AC | 162 ms
89,216 KB |
testcase_08 | AC | 160 ms
89,216 KB |
testcase_09 | AC | 158 ms
89,344 KB |
testcase_10 | WA | - |
testcase_11 | AC | 161 ms
89,472 KB |
testcase_12 | AC | 163 ms
89,216 KB |
testcase_13 | AC | 250 ms
90,752 KB |
testcase_14 | AC | 247 ms
90,752 KB |
testcase_15 | AC | 248 ms
90,752 KB |
testcase_16 | AC | 243 ms
90,752 KB |
testcase_17 | AC | 253 ms
91,136 KB |
testcase_18 | AC | 267 ms
91,136 KB |
testcase_19 | WA | - |
testcase_20 | AC | 328 ms
91,904 KB |
testcase_21 | AC | 359 ms
91,776 KB |
testcase_22 | AC | 393 ms
92,032 KB |
testcase_23 | AC | 371 ms
92,416 KB |
testcase_24 | AC | 349 ms
92,160 KB |
testcase_25 | AC | 374 ms
91,904 KB |
ソースコード
def main():from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsumfrom heapq import heapify, heappop, heappushfrom bisect import bisect_left, bisect_rightfrom copy import deepcopyimport copyimport randomfrom collections import deque,Counter,defaultdictfrom itertools import permutations,combinationsfrom 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_,itemgetterINF = 10**18mod1 = 10**9+7mod2 = 998244353#DecimalならPython#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!''''''class UnionFind():def __init__(self, n):self.n = nself.parents = [-1] * n#親だけself.edge = [0]*ndef find(self, x):if self.parents[x] < 0:return xelse: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, xself.edge[x] += 1if x == y:returnself.parents[x] += self.parents[y]self.edge[x] += self.edge[y]self.parents[y] = xdef 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_membersdef __str__(self):return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())N = int(input())uf = UnionFind(N)for _ in range(N-1):u,v = map(int, input().split())uf.union(u,v)if uf.group_count() == 1:print('Bob')else:print('Alice')if __name__ == '__main__':main()