結果

問題 No.763 Noelちゃんと木遊び
ユーザー daichan132daichan132
提出日時 2022-03-16 14:26:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,784 KB
実行使用メモリ 49,332 KB
最終ジャッジ日時 2023-10-24 19:25:21
合計ジャッジ時間 6,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
49,332 KB
testcase_01 AC 100 ms
15,652 KB
testcase_02 AC 220 ms
23,508 KB
testcase_03 AC 149 ms
19,268 KB
testcase_04 AC 113 ms
16,656 KB
testcase_05 AC 144 ms
18,756 KB
testcase_06 AC 271 ms
26,232 KB
testcase_07 AC 258 ms
25,732 KB
testcase_08 AC 158 ms
19,576 KB
testcase_09 AC 107 ms
16,440 KB
testcase_10 AC 54 ms
12,520 KB
testcase_11 AC 283 ms
26,632 KB
testcase_12 AC 251 ms
24,816 KB
testcase_13 AC 235 ms
24,460 KB
testcase_14 AC 213 ms
23,036 KB
testcase_15 AC 150 ms
19,076 KB
testcase_16 AC 43 ms
11,532 KB
testcase_17 AC 151 ms
19,112 KB
testcase_18 AC 275 ms
26,276 KB
testcase_19 AC 247 ms
24,996 KB
testcase_20 AC 246 ms
24,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def dfs(v, p, used: list, graph):
    paintable = True
    for n in graph[v]:
        if n == p:
            continue
        dfs(n, v, used, graph)
        if used[n]:
            paintable = False

    if paintable:
        used[v] = True


N = int(input())
graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)

used = [False] * N
dfs(0, -1, used, graph)

print(sum(used))
0