結果

問題 No.977 アリス仕掛けの摩天楼
コンテスト
ユーザー GrayCoder
提出日時 2020-01-31 23:03:29
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 626 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 442 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 145,252 KB
最終ジャッジ日時 2026-04-06 05:53:40
合計ジャッジ時間 45,663 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 16 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
from itertools import chain
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')
    if x == 2:
        num = list(chain.from_iterable(UV))
        if (min(num), max(num)) in UV:
            print('Bob')
    else:
        print('Alice')


main()
0