結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー |
![]() |
提出日時 | 2020-02-13 06:57:50 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 134 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-10-05 03:04:49 |
合計ジャッジ時間 | 5,106 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
class UnionFind(): def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def group_count(self): return len([0 for x in self.parents if x < 0]) N = int(input()) uf = UnionFind(N) a = [0] * N for _ in range(N-1): u, v = map(int, input().split()) uf.union(u, v) a[u] += 1 a[v] += 1 c = uf.group_count() if c >= 3: print("Alice") elif c == 2 and a.count(1): print("Alice") else: print("Bob")