結果

問題 No.763 Noelちゃんと木遊び
ユーザー daichan132
提出日時 2022-03-16 14:26:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 50,048 KB
最終ジャッジ日時 2024-09-24 13:17:35
合計ジャッジ時間 6,667 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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