結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ttrttr
提出日時 2020-02-01 19:19:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 12,008 KB
実行使用メモリ 13,156 KB
最終ジャッジ日時 2023-10-19 00:13:39
合計ジャッジ時間 4,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,252 KB
testcase_01 AC 31 ms
10,252 KB
testcase_02 AC 30 ms
10,252 KB
testcase_03 AC 30 ms
10,252 KB
testcase_04 AC 30 ms
10,252 KB
testcase_05 AC 30 ms
10,252 KB
testcase_06 AC 30 ms
10,252 KB
testcase_07 AC 30 ms
10,252 KB
testcase_08 AC 30 ms
10,252 KB
testcase_09 AC 31 ms
10,252 KB
testcase_10 WA -
testcase_11 AC 30 ms
10,252 KB
testcase_12 AC 30 ms
10,252 KB
testcase_13 AC 65 ms
10,460 KB
testcase_14 AC 63 ms
10,428 KB
testcase_15 AC 63 ms
10,432 KB
testcase_16 AC 64 ms
10,460 KB
testcase_17 AC 67 ms
10,532 KB
testcase_18 AC 132 ms
10,780 KB
testcase_19 WA -
testcase_20 AC 201 ms
11,572 KB
testcase_21 AC 308 ms
12,364 KB
testcase_22 AC 388 ms
13,156 KB
testcase_23 AC 455 ms
12,628 KB
testcase_24 AC 438 ms
12,628 KB
testcase_25 AC 448 ms
12,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

uf = UnionFind(N)
for _ in range(N-1):
    u,v = map(int, input().split())
    uf.unite(u+1, v+1)

ans = "Bob"
for i in range(2, N+1):
    if uf.isSameGroup(1, i):
        continue
    ans = "Alice"
    break
print(ans)
0