結果

問題 No.763 Noelちゃんと木遊び
ユーザー daichan132
提出日時 2022-03-16 14:26:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 49,664 KB
最終ジャッジ日時 2025-03-22 10:40:36
合計ジャッジ時間 7,249 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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