結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー GrayCoderGrayCoder
提出日時 2020-02-01 04:34:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 983 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 71,856 KB
最終ジャッジ日時 2023-10-18 23:30:59
合計ジャッジ時間 23,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 753 ms
53,536 KB
testcase_01 AC 766 ms
53,600 KB
testcase_02 AC 751 ms
53,600 KB
testcase_03 AC 748 ms
53,612 KB
testcase_04 AC 758 ms
53,600 KB
testcase_05 AC 757 ms
53,604 KB
testcase_06 AC 766 ms
53,604 KB
testcase_07 AC 760 ms
53,612 KB
testcase_08 AC 781 ms
53,608 KB
testcase_09 AC 770 ms
53,776 KB
testcase_10 AC 766 ms
53,616 KB
testcase_11 AC 755 ms
53,612 KB
testcase_12 AC 749 ms
53,608 KB
testcase_13 AC 777 ms
55,088 KB
testcase_14 AC 758 ms
55,088 KB
testcase_15 AC 757 ms
55,092 KB
testcase_16 AC 757 ms
55,088 KB
testcase_17 AC 759 ms
55,088 KB
testcase_18 AC 840 ms
57,088 KB
testcase_19 AC 823 ms
57,068 KB
testcase_20 AC 877 ms
60,540 KB
testcase_21 AC 942 ms
66,196 KB
testcase_22 AC 971 ms
70,848 KB
testcase_23 AC 983 ms
71,852 KB
testcase_24 AC 979 ms
71,856 KB
testcase_25 AC 964 ms
71,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0