結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2024-06-20 15:58:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 223 ms / 2,000 ms |
コード長 | 741 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 82,272 KB |
実行使用メモリ | 78,724 KB |
最終ジャッジ日時 | 2024-06-20 15:58:23 |
合計ジャッジ時間 | 4,434 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
def find(x): if tree[x]<0: return x tree[x]=find(tree[x]) return tree[x] def unite(x,y): x=find(x) y=find(y) if x==y: return if tree[x]>tree[y]: x,y=y,x tree[x]+=tree[y] tree[y]=x n=int(input()) tree=[-1]*n g=[0]*n for _ in range(n-1): a,b=map(int,input().split()) g[a]+=1 g[b]+=1 unite(a,b) cnt=[] for i in range(n): if tree[i]<0: cnt.append(i) if len(cnt)==1: print('Bob') elif len(cnt)>2: print('Alice') else: q=[g[cnt[0]],g[cnt[1]]] if 0 not in q: print('Alice') exit() if q[0]==0: s=cnt[1] else: s=cnt[0] bool=True for i in range(n): if find(i)==s: if g[i]!=2: bool=False if bool: print('Bob') else: print('Alice')