結果
| 問題 | No.977 アリス仕掛けの摩天楼 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-27 09:59:13 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,036 bytes |
| 記録 | |
| コンパイル時間 | 157 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2024-11-21 05:04:19 |
| 合計ジャッジ時間 | 4,692 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
ソースコード
class UnionFind:
def __init__(self, node):
self.parent = [-1 for _ in range(node)]
def find(self, target):
if self.parent[target] < 0:
return target
else:
self.parent[target] = self.find(self.parent[target])
return self.parent[target]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def union(self, x, y):
root_x = self.find(x)
root_y = self.find(y)
if root_x == root_y:
return
if self.parent[root_x] > self.parent[root_y]:
root_x, root_y = root_y, root_x
self.parent[root_x] += self.parent[root_y]
self.parent[root_y] = root_x
def get_size(self, x):
return -self.parent[self.find(x)]
def main():
islands = int(input())
uf = UnionFind(islands)
for _ in range(islands - 1):
u, v = map(int, input().split())
uf.union(u, v)
print("Bob" if uf.get_size(0) == islands else "Alice")
if __name__ == '__main__':
main()