結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー otsuri_114514otsuri_114514
提出日時 2020-02-04 23:45:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 11,932 KB
実行使用メモリ 13,536 KB
最終ジャッジ日時 2023-10-21 06:42:04
合計ジャッジ時間 3,527 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,124 KB
testcase_01 AC 30 ms
10,124 KB
testcase_02 AC 30 ms
10,124 KB
testcase_03 AC 30 ms
10,124 KB
testcase_04 AC 30 ms
10,124 KB
testcase_05 AC 30 ms
10,124 KB
testcase_06 AC 31 ms
10,124 KB
testcase_07 AC 30 ms
10,124 KB
testcase_08 AC 31 ms
10,124 KB
testcase_09 AC 31 ms
10,124 KB
testcase_10 AC 30 ms
10,124 KB
testcase_11 AC 31 ms
10,124 KB
testcase_12 AC 31 ms
10,124 KB
testcase_13 AC 53 ms
10,368 KB
testcase_14 AC 51 ms
10,432 KB
testcase_15 AC 52 ms
10,432 KB
testcase_16 AC 51 ms
10,368 KB
testcase_17 AC 52 ms
10,408 KB
testcase_18 AC 96 ms
10,896 KB
testcase_19 AC 104 ms
11,160 KB
testcase_20 AC 150 ms
11,952 KB
testcase_21 AC 229 ms
13,008 KB
testcase_22 AC 291 ms
13,536 KB
testcase_23 AC 284 ms
13,272 KB
testcase_24 AC 270 ms
13,272 KB
testcase_25 AC 292 ms
13,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

class Union_find:
    
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rank=[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,y=self.find_root(x),self.find_root(y)
    
        if x==y: return 
        elif self.rank[x]>self.rank[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]: self.rank[y]+=1
    
    def same(self,x,y):
        return self.find_root(x)==self.find_root(y)
    
    def count(self,x):
        return -self.root[self.find_root(x)]

n=int(input().rstrip())
g=Union_find(n-1)
e=[0]*n
for _ in range(n-1):
    u,v=map(int,input().split())
    g.unite(u,v)
    e[u]+=1
    e[v]+=1

r=len(set(g.find_root(i) for i in range(n)))
if r==1:
    print("Bob")
elif r>=3:
    print("Alice")
else:
    print("Alice" if 1 in e else "Bob")
0