結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー toyuzukotoyuzuko
提出日時 2020-03-18 23:03:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 34,224 KB
最終ジャッジ日時 2023-08-20 20:23:40
合計ジャッジ時間 4,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 AC 16 ms
7,940 KB
testcase_03 AC 16 ms
7,956 KB
testcase_04 AC 16 ms
7,804 KB
testcase_05 AC 16 ms
7,952 KB
testcase_06 AC 16 ms
7,820 KB
testcase_07 AC 16 ms
7,888 KB
testcase_08 AC 16 ms
7,800 KB
testcase_09 AC 16 ms
7,828 KB
testcase_10 AC 16 ms
7,852 KB
testcase_11 AC 16 ms
7,920 KB
testcase_12 AC 17 ms
7,940 KB
testcase_13 AC 52 ms
10,848 KB
testcase_14 AC 51 ms
10,800 KB
testcase_15 AC 52 ms
10,808 KB
testcase_16 AC 52 ms
10,892 KB
testcase_17 AC 52 ms
10,780 KB
testcase_18 AC 126 ms
16,140 KB
testcase_19 AC 130 ms
16,056 KB
testcase_20 AC 194 ms
20,660 KB
testcase_21 AC 292 ms
27,700 KB
testcase_22 AC 387 ms
32,928 KB
testcase_23 AC 464 ms
33,412 KB
testcase_24 AC 443 ms
34,224 KB
testcase_25 AC 450 ms
33,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Graph(): #non-directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]].append(e[1])
            self.graph[e[1]].append(e[0])
            self.deg[e[0]] += 1
            self.deg[e[1]] += 1

    def DFS(self,s):
        visited = [0 for _ in range(self.n)]
        visited[s] = 1
        stack = [s]
        while stack:
            node = stack.pop()
            for adj in self.graph[node]:
                if not visited[adj]:
                    visited[adj] = 1
                    stack.append(adj)
        return visited

N = int(input())
E = [tuple(map(int, input().split())) for _ in range(N - 1)]

G = Graph(N, E)
D = G.DFS(0) if G.deg[0] > 0 else G.DFS(1)

print('Bob' if all(D) or all([D[i] and G.deg[i] == 2 for i in range(N) if G.deg[i] != 0]) else 'Alice')
0