結果
| 問題 | No.977 アリス仕掛けの摩天楼 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-01 04:34:36 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1,636 ms / 2,000 ms |
| + 419µs | |
| コード長 | 686 bytes |
| 記録 | |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 21,408 KB |
| 実行使用メモリ | 85,136 KB |
| 最終ジャッジ日時 | 2026-08-30 10:08:21 |
| 合計ジャッジ時間 | 43,162 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
from sys import stdin
def main():
input = lambda: stdin.readline()[:-1]
N = int(input())
UV = [tuple(map(int, input().split())) for _ in [0] * (N - 1)]
l = list(zip(*UV))
d = [1] * len(UV)
a = csr_matrix((d, (l[0], l[1])), (N, N))
x = connected_components(a, return_labels=0)
if x == 1:
print('Bob')
elif x == 2:
cnt = [0] * N
for u, v in UV:
cnt[u] += 1
cnt[v] += 1
if cnt.count(2) == N - 1:
print('Bob')
else:
print('Alice')
else:
print('Alice')
main()