結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 12354865271235486527
提出日時 2020-02-13 06:57:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-15 09:45:17
合計ジャッジ時間 5,493 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 37 ms
10,752 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 32 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 69 ms
11,136 KB
testcase_14 AC 71 ms
11,008 KB
testcase_15 AC 69 ms
11,008 KB
testcase_16 AC 68 ms
11,008 KB
testcase_17 AC 70 ms
11,264 KB
testcase_18 AC 149 ms
11,648 KB
testcase_19 AC 151 ms
11,776 KB
testcase_20 AC 231 ms
12,288 KB
testcase_21 AC 343 ms
12,928 KB
testcase_22 AC 437 ms
13,696 KB
testcase_23 AC 440 ms
13,312 KB
testcase_24 AC 432 ms
13,440 KB
testcase_25 AC 465 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind():
    def __init__(self, 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 group_count(self):
        return len([0 for x in self.parents if x < 0])

N = int(input())
uf = UnionFind(N)
a = [0] * N
for _ in range(N-1):
    u, v = map(int, input().split())
    uf.union(u, v)
    a[u] += 1
    a[v] += 1
c = uf.group_count()
if c >= 3:
    print("Alice")
elif c == 2 and a.count(1):
    print("Alice")
else:
    print("Bob")
0