結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー TakoKurageTakoKurage
提出日時 2020-01-31 23:25:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,080 KB
実行使用メモリ 32,964 KB
最終ジャッジ日時 2023-10-17 12:40:14
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,180 KB
testcase_01 AC 29 ms
10,180 KB
testcase_02 AC 29 ms
10,180 KB
testcase_03 AC 28 ms
10,180 KB
testcase_04 AC 28 ms
10,180 KB
testcase_05 AC 28 ms
10,180 KB
testcase_06 AC 29 ms
10,180 KB
testcase_07 AC 28 ms
10,188 KB
testcase_08 AC 28 ms
10,192 KB
testcase_09 AC 28 ms
10,192 KB
testcase_10 AC 29 ms
10,192 KB
testcase_11 AC 29 ms
10,192 KB
testcase_12 AC 28 ms
10,192 KB
testcase_13 AC 50 ms
12,576 KB
testcase_14 AC 49 ms
12,836 KB
testcase_15 AC 49 ms
12,836 KB
testcase_16 AC 50 ms
12,576 KB
testcase_17 AC 50 ms
12,576 KB
testcase_18 AC 93 ms
16,896 KB
testcase_19 AC 100 ms
16,896 KB
testcase_20 AC 148 ms
21,180 KB
testcase_21 AC 229 ms
27,256 KB
testcase_22 AC 305 ms
32,064 KB
testcase_23 AC 306 ms
32,964 KB
testcase_24 AC 301 ms
32,964 KB
testcase_25 AC 308 ms
32,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]

N, *AB = map(int, open(0).read().split())

uf = UnionFind(N)

E = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)
    uf.union(a, b)

one = sum(1 for e in E if len(e) == 1)
C = len(set(uf.find(i) for i in range(N)))

if C == 1 or (C == 2 and one == 0):
    print("Bob")
else:
    print("Alice")
0