結果

問題 No.763 Noelちゃんと木遊び
ユーザー titan23titan23
提出日時 2022-06-11 13:39:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 180,156 KB
最終ジャッジ日時 2023-10-21 22:23:20
合計ジャッジ時間 7,478 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 321 ms
180,156 KB
testcase_01 AC 146 ms
82,956 KB
testcase_02 AC 259 ms
92,788 KB
testcase_03 AC 195 ms
87,444 KB
testcase_04 AC 163 ms
84,044 KB
testcase_05 AC 199 ms
87,316 KB
testcase_06 AC 297 ms
95,648 KB
testcase_07 AC 294 ms
95,640 KB
testcase_08 AC 207 ms
88,004 KB
testcase_09 AC 174 ms
84,420 KB
testcase_10 AC 115 ms
79,760 KB
testcase_11 AC 314 ms
95,912 KB
testcase_12 AC 279 ms
94,124 KB
testcase_13 AC 272 ms
93,752 KB
testcase_14 AC 270 ms
91,624 KB
testcase_15 AC 212 ms
87,276 KB
testcase_16 AC 107 ms
78,064 KB
testcase_17 AC 204 ms
87,432 KB
testcase_18 AC 311 ms
96,100 KB
testcase_19 AC 288 ms
94,360 KB
testcase_20 AC 328 ms
94,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)

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

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