結果

問題 No.763 Noelちゃんと木遊び
ユーザー tcltktcltk
提出日時 2021-08-24 05:26:47
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 824 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 102,660 KB
最終ジャッジ日時 2024-04-26 07:52:29
合計ジャッジ時間 6,401 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 179 ms
92,992 KB
testcase_02 AC 227 ms
98,816 KB
testcase_03 AC 197 ms
95,620 KB
testcase_04 AC 185 ms
93,928 KB
testcase_05 AC 202 ms
95,488 KB
testcase_06 AC 259 ms
100,608 KB
testcase_07 AC 261 ms
99,968 KB
testcase_08 AC 207 ms
96,036 KB
testcase_09 AC 192 ms
93,520 KB
testcase_10 AC 156 ms
91,264 KB
testcase_11 AC 249 ms
100,992 KB
testcase_12 AC 250 ms
99,908 KB
testcase_13 AC 254 ms
99,584 KB
testcase_14 AC 245 ms
98,688 KB
testcase_15 AC 214 ms
95,232 KB
testcase_16 AC 166 ms
90,732 KB
testcase_17 AC 224 ms
95,712 KB
testcase_18 AC 294 ms
100,832 KB
testcase_19 AC 289 ms
100,332 KB
testcase_20 AC 270 ms
99,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """12
# 1 2
# 2 3
# 3 4
# 4 5
# 1 6
# 6 7
# 6 8
# 7 11
# 7 12
# 8 9
# 9 10

# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def dfs(parent, p):

    leaf = True
    for p1 in G[p]:
        if p1 == parent:
            continue
        dfs(p, p1)
        if Deleted[p1] == 0:
            leaf = False

    if not leaf:
        Deleted[p] = 1


N = int(input())
G = [list() for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    G[u-1].append(v-1)
    G[v-1].append(u-1)

Deleted = [0] * N
dfs(-1, 0)

ans = Deleted.count(0)
print(ans)
0