結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tamatotamato
提出日時 2020-01-31 21:37:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,473 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,488 KB
実行使用メモリ 104,364 KB
最終ジャッジ日時 2023-10-17 08:55:52
合計ジャッジ時間 4,476 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,256 KB
testcase_01 AC 37 ms
53,256 KB
testcase_02 AC 39 ms
53,256 KB
testcase_03 AC 38 ms
53,256 KB
testcase_04 AC 38 ms
53,256 KB
testcase_05 AC 38 ms
53,256 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 39 ms
53,256 KB
testcase_09 AC 39 ms
53,256 KB
testcase_10 AC 38 ms
53,296 KB
testcase_11 AC 40 ms
53,256 KB
testcase_12 AC 39 ms
53,296 KB
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 366 ms
101,896 KB
testcase_24 AC 387 ms
104,364 KB
testcase_25 AC 363 ms
102,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    # 単純に橋となる辺を返す
    def bridge(G, N):
        result = set()
        label = [None] * N
        gen = 0
        cost = [0] * N

        def dfs(u, p):
            nonlocal gen
            res = 0
            for v in G[u]:
                if v == p:
                    continue
                if label[v] is not None:
                    if label[v] < label[u]:
                        cost[v] += 1
                        res += 1
                else:
                    label[v] = gen;
                    gen += 1
                    r = dfs(v, u)
                    if r == 0:
                        result.add((u, v) if u < v else (v, u))
                    res += r
            res -= cost[u]
            return res

        for v in range(N):
            if not label[v]:
                label[v] = gen;
                gen += 1
                r = dfs(v, -1)
                assert r == 0, r
        return result

    N = int(input())
    adj = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v = map(int, input().split())
        adj[u].append(v)
        adj[v].append(u)
    cnt_0 = 0
    for i in range(N):
        if len(adj[i]) == 0:
            cnt_0 += 1

    flg = len(bridge(adj, N))
    
    if cnt_0 >= 2:
        print('Alice')
    elif cnt_0 == 1 and flg:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()
0