結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | paruf4 |
提出日時 | 2020-06-20 18:49:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 469 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 10,968 KB |
実行使用メモリ | 14,324 KB |
最終ジャッジ日時 | 2023-09-16 17:42:15 |
合計ジャッジ時間 | 4,695 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,584 KB |
testcase_01 | AC | 19 ms
8,756 KB |
testcase_02 | AC | 20 ms
8,544 KB |
testcase_03 | AC | 19 ms
8,640 KB |
testcase_04 | AC | 20 ms
8,660 KB |
testcase_05 | AC | 19 ms
8,744 KB |
testcase_06 | AC | 20 ms
8,604 KB |
testcase_07 | AC | 20 ms
8,660 KB |
testcase_08 | AC | 19 ms
8,692 KB |
testcase_09 | AC | 20 ms
8,748 KB |
testcase_10 | AC | 21 ms
8,724 KB |
testcase_11 | AC | 20 ms
8,644 KB |
testcase_12 | AC | 20 ms
8,584 KB |
testcase_13 | AC | 59 ms
9,012 KB |
testcase_14 | AC | 58 ms
9,076 KB |
testcase_15 | AC | 58 ms
9,016 KB |
testcase_16 | AC | 60 ms
8,948 KB |
testcase_17 | AC | 59 ms
9,156 KB |
testcase_18 | AC | 142 ms
10,180 KB |
testcase_19 | AC | 143 ms
10,192 KB |
testcase_20 | AC | 230 ms
11,256 KB |
testcase_21 | AC | 349 ms
11,668 KB |
testcase_22 | AC | 458 ms
14,040 KB |
testcase_23 | AC | 452 ms
14,324 KB |
testcase_24 | AC | 453 ms
14,256 KB |
testcase_25 | AC | 469 ms
14,292 KB |
ソースコード
class UnionFind: def __init__(self, n): self.p = [-1]*n # union by rank self.r = [1]*n def find(self, x): if self.p[x] < 0: return x else: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): rx, ry = self.find(x), self.find(y) if rx != ry: if self.r[rx] > self.r[ry]: rx, ry = ry, rx if self.r[rx] == self.r[ry]: self.r[ry] += 1 self.p[ry] += self.p[rx] self.p[rx] = ry def same(self, x, y): return self.find(x) == self.find(y) def count_member(self, x): return -self.p[self.find(x)] n=int(input()) uf=UnionFind(n) edge=[0]*n for i in range(n-1): u,v=map(int,input().split()) uf.union(u,v) edge[u]+=1 edge[v]+=1 c=[0]*n for i in range(n): c[i]=uf.count_member(i) c=set(c) from collections import Counter if len(c)==1: print("Bob") elif len(c)>=3: print("Alice") else: c=Counter(edge) if c[2]==n-1: print("Bob") else: print("Alice")