結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー stngstng
提出日時 2022-08-16 20:57:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,140 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 91,200 KB
最終ジャッジ日時 2024-04-14 14:42:46
合計ジャッジ時間 6,088 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,892 KB
testcase_01 AC 38 ms
52,940 KB
testcase_02 AC 38 ms
53,180 KB
testcase_03 AC 38 ms
52,600 KB
testcase_04 AC 37 ms
52,536 KB
testcase_05 AC 38 ms
54,284 KB
testcase_06 AC 39 ms
53,936 KB
testcase_07 AC 40 ms
54,376 KB
testcase_08 AC 39 ms
53,548 KB
testcase_09 AC 40 ms
54,000 KB
testcase_10 WA -
testcase_11 AC 40 ms
54,200 KB
testcase_12 AC 39 ms
53,336 KB
testcase_13 AC 157 ms
78,816 KB
testcase_14 AC 154 ms
78,368 KB
testcase_15 AC 150 ms
78,264 KB
testcase_16 AC 156 ms
78,204 KB
testcase_17 AC 166 ms
78,820 KB
testcase_18 AC 205 ms
80,624 KB
testcase_19 WA -
testcase_20 AC 282 ms
84,512 KB
testcase_21 AC 348 ms
87,772 KB
testcase_22 AC 406 ms
91,200 KB
testcase_23 AC 413 ms
90,532 KB
testcase_24 AC 343 ms
91,024 KB
testcase_25 AC 413 ms
90,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n = int(input())
uv = [[] for i in range(n)]
ki = UnionFind(n+1)
for i in range(n-1):
    u,v = map(int,input().split())
    uv[u].append(v)
    uv[v].append(u)
    if not ki.same_check(u,v):
        ki.union(u,v)

idx = ki.find(0)
for i in range(n):
    if ki.find(i) != idx:
        print("Alice")
        exit()
print("Bob")
0