結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2020-02-04 23:45:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 268 ms / 2,000 ms |
コード長 | 1,671 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 14,336 KB |
最終ジャッジ日時 | 2024-09-21 07:51:54 |
合計ジャッジ時間 | 3,187 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#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")