結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tyawanmusityawanmusi
提出日時 2020-01-31 21:28:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 805 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 11,976 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2023-10-17 08:42:50
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,276 KB
testcase_01 AC 29 ms
10,276 KB
testcase_02 AC 29 ms
10,276 KB
testcase_03 AC 29 ms
10,276 KB
testcase_04 AC 29 ms
10,276 KB
testcase_05 AC 29 ms
10,276 KB
testcase_06 AC 28 ms
10,276 KB
testcase_07 AC 29 ms
10,276 KB
testcase_08 AC 29 ms
10,276 KB
testcase_09 AC 30 ms
10,276 KB
testcase_10 WA -
testcase_11 AC 29 ms
10,276 KB
testcase_12 AC 29 ms
10,276 KB
testcase_13 AC 61 ms
10,488 KB
testcase_14 AC 63 ms
10,456 KB
testcase_15 AC 64 ms
10,460 KB
testcase_16 AC 62 ms
10,488 KB
testcase_17 AC 61 ms
10,560 KB
testcase_18 AC 128 ms
10,808 KB
testcase_19 WA -
testcase_20 AC 196 ms
11,600 KB
testcase_21 AC 298 ms
12,392 KB
testcase_22 AC 374 ms
13,184 KB
testcase_23 AC 390 ms
12,656 KB
testcase_24 AC 373 ms
12,656 KB
testcase_25 AC 383 ms
12,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)]
n=int(input())
u=UnionFind(n)
for i in range(n-1):
  a,b=map(int,input().split())
  u.Unite(a,b)
if u.Count(0)==n:print("Bob")
else:print("Alice")
0