結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー stngstng
提出日時 2022-08-16 22:06:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 92,096 KB
最終ジャッジ日時 2024-04-14 15:44:20
合計ジャッジ時間 5,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,988 KB
testcase_01 AC 43 ms
54,560 KB
testcase_02 AC 43 ms
54,188 KB
testcase_03 AC 44 ms
54,416 KB
testcase_04 AC 42 ms
54,176 KB
testcase_05 AC 42 ms
54,568 KB
testcase_06 AC 43 ms
55,552 KB
testcase_07 AC 44 ms
54,788 KB
testcase_08 AC 44 ms
55,540 KB
testcase_09 AC 45 ms
55,240 KB
testcase_10 WA -
testcase_11 AC 44 ms
55,460 KB
testcase_12 AC 43 ms
55,552 KB
testcase_13 AC 172 ms
78,880 KB
testcase_14 AC 175 ms
79,512 KB
testcase_15 AC 163 ms
79,312 KB
testcase_16 AC 172 ms
79,104 KB
testcase_17 AC 176 ms
79,720 KB
testcase_18 AC 225 ms
82,232 KB
testcase_19 WA -
testcase_20 AC 312 ms
85,888 KB
testcase_21 AC 376 ms
89,516 KB
testcase_22 AC 446 ms
92,052 KB
testcase_23 AC 427 ms
91,560 KB
testcase_24 AC 365 ms
92,096 KB
testcase_25 AC 428 ms
91,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
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)
    ff,ss = u,v
    if not ki.same_check(u,v):
        ki.union(u,v)

f = True
idx = ki.find(0)
gr = set()
gr.add(idx)
for i in range(n):
    if ki.find(i) != idx:
        gr.add(ki.find(i))
        f = False
if f == True:
    print("Bob")
    exit()
elif len(gr) >= 2:
    print("Alice")
    exit()

d = deque()
d.append(ss)
li = [0]*n
li[ff] = 1
li[ss] = 1

js = 0
for i in range(n):
    if len(uv[i]) == 2:
        js += 1

if js != n-1:
    print("Alice")
else:
    print("Bob")
0