結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー paruf4paruf4
提出日時 2020-06-20 08:51:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 13,676 KB
最終ジャッジ日時 2023-09-16 16:54:52
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,244 KB
testcase_01 AC 16 ms
8,196 KB
testcase_02 AC 16 ms
8,244 KB
testcase_03 AC 16 ms
8,300 KB
testcase_04 AC 16 ms
8,300 KB
testcase_05 AC 16 ms
8,196 KB
testcase_06 AC 16 ms
8,336 KB
testcase_07 AC 16 ms
8,252 KB
testcase_08 AC 16 ms
8,348 KB
testcase_09 AC 16 ms
8,328 KB
testcase_10 WA -
testcase_11 AC 16 ms
8,232 KB
testcase_12 AC 17 ms
8,316 KB
testcase_13 AC 58 ms
8,660 KB
testcase_14 AC 55 ms
8,612 KB
testcase_15 AC 55 ms
8,756 KB
testcase_16 AC 56 ms
8,752 KB
testcase_17 AC 57 ms
8,768 KB
testcase_18 AC 140 ms
9,932 KB
testcase_19 WA -
testcase_20 AC 220 ms
10,772 KB
testcase_21 AC 341 ms
10,880 KB
testcase_22 AC 438 ms
13,288 KB
testcase_23 AC 461 ms
13,676 KB
testcase_24 AC 440 ms
13,620 KB
testcase_25 AC 460 ms
13,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n
 
    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]
 
    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
 
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count_member(self, x):
        return -self.p[self.find(x)]

n=int(input())
uf=UnionFind(n)
for i in range(n-1):
  u,v=map(int,input().split())
  if not uf.same(u,v):
    uf.union(u,v)
c=[0]*n
for i in range(n):
  c[i]=uf.count_member(i)

for cc in c:
  if cc!=n:
    print("Alice")
    exit(0)
print("Bob")
0