結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
11,008 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 25 ms
11,008 KB
testcase_03 AC 25 ms
10,752 KB
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 27 ms
10,880 KB
testcase_07 AC 25 ms
10,752 KB
testcase_08 AC 25 ms
10,880 KB
testcase_09 AC 25 ms
10,752 KB
testcase_10 AC 24 ms
10,880 KB
testcase_11 AC 25 ms
10,880 KB
testcase_12 AC 24 ms
11,008 KB
testcase_13 AC 75 ms
13,184 KB
testcase_14 AC 71 ms
13,184 KB
testcase_15 AC 76 ms
13,056 KB
testcase_16 AC 75 ms
13,056 KB
testcase_17 AC 78 ms
13,056 KB
testcase_18 AC 184 ms
18,300 KB
testcase_19 AC 183 ms
18,048 KB
testcase_20 AC 264 ms
22,792 KB
testcase_21 AC 423 ms
28,168 KB
testcase_22 AC 548 ms
34,696 KB
testcase_23 AC 579 ms
36,616 KB
testcase_24 AC 568 ms
36,880 KB
testcase_25 AC 646 ms
36,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class union_find():
    def __init__(self, num):
        self.parents = [-1 for i in range(n)]
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        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(self.roots())
        
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


n = int(input())
dicts = {i:[] for i in range(n)}
lists = [-1 for i in range(n)]

a = union_find(n)
for i in range(n - 1):
    te, mp = map(int, input().split())
    dicts[te] += [mp]
    dicts[mp] += [te]


for i in range(n):
    for j in dicts[i]:
        if j > i:
            a.union(i, j)
    

if a.group_count() < 2:
    print('Bob')
elif a.group_count() > 2:
    print('Alice')
else:
    if len(list(filter(lambda x:len(x)==2, dicts.values()))) == n - 1:
        print('Bob')
    else:
        print('Alice')
0