結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2024-06-20 15:39:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 730 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 78,496 KB |
最終ジャッジ日時 | 2024-06-20 15:39:17 |
合計ジャッジ時間 | 5,002 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 WA * 3 |
ソースコード
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') 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')