結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | tyawanmusi |
提出日時 | 2020-01-31 23:09:14 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
AC
|
実行時間 | 457 ms / 2,000 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 101 ms |
コンパイル使用メモリ | 11,928 KB |
実行使用メモリ | 13,912 KB |
最終ジャッジ日時 | 2023-10-17 12:12:00 |
合計ジャッジ時間 | 4,719 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,260 KB |
testcase_01 | AC | 29 ms
10,260 KB |
testcase_02 | AC | 30 ms
10,260 KB |
testcase_03 | AC | 30 ms
10,260 KB |
testcase_04 | AC | 30 ms
10,260 KB |
testcase_05 | AC | 30 ms
10,260 KB |
testcase_06 | AC | 30 ms
10,260 KB |
testcase_07 | AC | 30 ms
10,260 KB |
testcase_08 | AC | 30 ms
10,260 KB |
testcase_09 | AC | 30 ms
10,260 KB |
testcase_10 | AC | 30 ms
10,260 KB |
testcase_11 | AC | 31 ms
10,260 KB |
testcase_12 | AC | 30 ms
10,260 KB |
testcase_13 | AC | 70 ms
10,480 KB |
testcase_14 | AC | 68 ms
10,480 KB |
testcase_15 | AC | 68 ms
10,480 KB |
testcase_16 | AC | 69 ms
10,480 KB |
testcase_17 | AC | 70 ms
10,540 KB |
testcase_18 | AC | 150 ms
11,008 KB |
testcase_19 | AC | 153 ms
11,272 KB |
testcase_20 | AC | 234 ms
12,064 KB |
testcase_21 | AC | 356 ms
13,120 KB |
testcase_22 | AC | 457 ms
13,912 KB |
testcase_23 | AC | 456 ms
13,384 KB |
testcase_24 | AC | 447 ms
13,384 KB |
testcase_25 | AC | 456 ms
13,384 KB |
ソースコード
import sys;sys.setrecursionlimit(10**9) class UnionFind(): def __init__(self,n): self.n=[-1]*n self.r=[0]*n def Find_Root(self,x): if self.n[x]<0: return x else: self.n[x]=self.Find_Root(self.n[x]) return self.n[x] def Unite(self,x,y): x=self.Find_Root(x) y=self.Find_Root(y) if x==y:return elif self.r[x]>self.r[y]: self.n[x]+=self.n[y] self.n[y]=x else: self.n[y]+=self.n[x] self.n[x]=y if self.r[x]==self.r[y]: self.r[y]+=1 def Root_Same(self,x,y): return self.Find_Root(x)==self.Find_Root(y) def Count(self,x): return -self.n[self.Find_Root(x)] def Is_Root(self,x): return self.Find_Root(x)==x n=int(input()) u=UnionFind(n) x=[0]*n for i in range(n-1): a,b=map(int,input().split()) u.Unite(a,b) x[a]+=1 x[b]+=1 c=[] for i in range(n): if u.Is_Root(i):c.append(i) if len(c)==1:print("Bob") elif len(c)==2: if x.count(0)==1 and x.count(2)==n-1:print("Bob") else:print("Alice") else:print("Alice")