結果

問題 No.763 Noelちゃんと木遊び
ユーザー titan23titan23
提出日時 2022-06-11 13:40:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 181,376 KB
最終ジャッジ日時 2023-10-21 22:24:03
合計ジャッジ時間 5,067 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 313 ms
181,376 KB
testcase_01 AC 99 ms
82,556 KB
testcase_02 AC 173 ms
91,456 KB
testcase_03 AC 126 ms
86,436 KB
testcase_04 AC 106 ms
83,464 KB
testcase_05 AC 121 ms
86,076 KB
testcase_06 AC 201 ms
94,740 KB
testcase_07 AC 205 ms
94,164 KB
testcase_08 AC 132 ms
87,024 KB
testcase_09 AC 107 ms
83,212 KB
testcase_10 AC 88 ms
78,700 KB
testcase_11 AC 200 ms
95,132 KB
testcase_12 AC 185 ms
93,080 KB
testcase_13 AC 184 ms
92,720 KB
testcase_14 AC 162 ms
90,812 KB
testcase_15 AC 134 ms
86,292 KB
testcase_16 AC 78 ms
77,596 KB
testcase_17 AC 125 ms
86,376 KB
testcase_18 AC 200 ms
94,828 KB
testcase_19 AC 178 ms
93,220 KB
testcase_20 AC 190 ms
93,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

##################

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

dp = [[0, 0] for _ in range(n)]

def dfs(p, v):
  ch0, ch1 = 0, 0
  for x in G[v]:
    if x == p:
      continue
    dfs(v, x)
    ch0 += max(dp[x][0], dp[x][1])
    ch1 += max(dp[x][0], dp[x][1]-1)
  dp[v][0] = ch0
  dp[v][1] = ch1 + 1

dfs(-1, 0)
# print(*dp)
print(max(dp[0]))
0