結果

問題 No.763 Noelちゃんと木遊び
ユーザー kept1994kept1994
提出日時 2022-05-05 18:03:42
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 184,652 KB
最終ジャッジ日時 2023-09-18 02:52:46
合計ジャッジ時間 7,377 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
184,652 KB
testcase_01 AC 180 ms
82,620 KB
testcase_02 AC 285 ms
88,628 KB
testcase_03 AC 220 ms
85,076 KB
testcase_04 AC 198 ms
84,328 KB
testcase_05 AC 213 ms
85,108 KB
testcase_06 AC 317 ms
90,852 KB
testcase_07 AC 298 ms
90,100 KB
testcase_08 AC 221 ms
84,956 KB
testcase_09 AC 194 ms
83,464 KB
testcase_10 AC 148 ms
80,328 KB
testcase_11 AC 311 ms
90,512 KB
testcase_12 AC 290 ms
89,624 KB
testcase_13 AC 286 ms
89,228 KB
testcase_14 AC 259 ms
87,952 KB
testcase_15 AC 215 ms
84,684 KB
testcase_16 AC 140 ms
79,612 KB
testcase_17 AC 222 ms
85,428 KB
testcase_18 AC 308 ms
91,024 KB
testcase_19 AC 286 ms
89,364 KB
testcase_20 AC 287 ms
89,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 9)

def main():
    N = int(input())
    G = [[] for _ in range(N)]
    dp = [0] * N
    for _ in range(N - 1):
        u, v = map(int, input().split())
        G[u - 1].append(v - 1)
        G[v - 1].append(u - 1)
    
    def dfs(now: int, pre: int):
        selectable = True
        for next in G[now]:
            if next == pre:
                continue
            dfs(next, now)
            if dp[next]:
                selectable = False
        if selectable:
            dp[now] = 1
        return

    dfs(0, -1)
    print(sum(dp))
    return

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