結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー O2MTO2MT
提出日時 2020-12-04 17:20:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 10,584 KB
最終ジャッジ日時 2023-10-13 06:47:17
合計ジャッジ時間 4,530 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,620 KB
testcase_01 AC 18 ms
8,624 KB
testcase_02 AC 17 ms
8,636 KB
testcase_03 AC 17 ms
8,572 KB
testcase_04 AC 17 ms
8,668 KB
testcase_05 AC 17 ms
8,628 KB
testcase_06 AC 17 ms
8,624 KB
testcase_07 AC 17 ms
8,584 KB
testcase_08 AC 17 ms
8,620 KB
testcase_09 AC 17 ms
8,720 KB
testcase_10 WA -
testcase_11 AC 17 ms
8,636 KB
testcase_12 AC 17 ms
8,672 KB
testcase_13 AC 45 ms
8,732 KB
testcase_14 AC 46 ms
8,732 KB
testcase_15 AC 46 ms
8,744 KB
testcase_16 AC 46 ms
8,816 KB
testcase_17 AC 45 ms
8,924 KB
testcase_18 AC 108 ms
8,980 KB
testcase_19 WA -
testcase_20 AC 167 ms
9,620 KB
testcase_21 AC 261 ms
10,144 KB
testcase_22 AC 327 ms
10,584 KB
testcase_23 AC 344 ms
10,300 KB
testcase_24 AC 338 ms
10,400 KB
testcase_25 AC 325 ms
10,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
 
N = int(input())
uf = UnionFind(N)
for _ in range(N-1):
    v1,v2 = map(int,input().split())
    uf.union(v1,v2)
ans = "Alice"
if uf.size(0) == N:
    ans = "Bob"
print(ans)
0