結果

問題 No.763 Noelちゃんと木遊び
ユーザー tcltktcltk
提出日時 2021-08-24 05:30:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 177,944 KB
最終ジャッジ日時 2024-04-26 07:55:20
合計ジャッジ時間 6,758 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
177,944 KB
testcase_01 AC 186 ms
92,832 KB
testcase_02 AC 258 ms
98,492 KB
testcase_03 AC 201 ms
96,000 KB
testcase_04 AC 186 ms
93,600 KB
testcase_05 AC 201 ms
95,372 KB
testcase_06 AC 279 ms
100,916 KB
testcase_07 AC 271 ms
100,600 KB
testcase_08 AC 219 ms
96,128 KB
testcase_09 AC 199 ms
93,660 KB
testcase_10 AC 168 ms
90,560 KB
testcase_11 AC 276 ms
101,028 KB
testcase_12 AC 258 ms
99,840 KB
testcase_13 AC 255 ms
99,524 KB
testcase_14 AC 254 ms
98,276 KB
testcase_15 AC 208 ms
95,400 KB
testcase_16 AC 163 ms
90,576 KB
testcase_17 AC 214 ms
95,392 KB
testcase_18 AC 280 ms
100,988 KB
testcase_19 AC 277 ms
99,592 KB
testcase_20 AC 269 ms
99,776 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):

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

    Deleted[p] = delete


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 = [False] * N
dfs(-1, 0)

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