結果

問題 No.763 Noelちゃんと木遊び
ユーザー standstillstandstill
提出日時 2021-05-14 23:39:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 559 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 102,668 KB
最終ジャッジ日時 2024-04-10 04:20:35
合計ジャッジ時間 7,813 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 186 ms
84,992 KB
testcase_02 AC 336 ms
95,600 KB
testcase_03 AC 242 ms
89,504 KB
testcase_04 AC 204 ms
85,972 KB
testcase_05 AC 238 ms
89,012 KB
testcase_06 AC 358 ms
99,016 KB
testcase_07 AC 365 ms
98,724 KB
testcase_08 AC 252 ms
90,596 KB
testcase_09 AC 208 ms
85,820 KB
testcase_10 AC 136 ms
80,300 KB
testcase_11 AC 380 ms
99,248 KB
testcase_12 AC 342 ms
96,736 KB
testcase_13 AC 332 ms
97,092 KB
testcase_14 AC 297 ms
94,188 KB
testcase_15 AC 238 ms
89,156 KB
testcase_16 AC 126 ms
79,236 KB
testcase_17 AC 260 ms
89,596 KB
testcase_18 AC 367 ms
98,948 KB
testcase_19 AC 359 ms
97,240 KB
testcase_20 AC 338 ms
96,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  N = int(input())
  G = [[] for _ in range(N + 5)]
  for i in range(N - 1):
    u, v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)

  dp = [[0] * 5 for _ in range(N + 5)]
  root = 1
  dfs(root, -1, G, dp)
  ans = max(dp[root][0], dp[root][1])
  print(f"{ans}")
  return


def dfs(u, parent, G, dp):
  dp[u][0], dp[u][1] = 1, 0
  for v in G[u]:
    if v == parent: continue
    dfs(v, u, G, dp)
    dp[u][0] += max(dp[v][0] - 1, dp[v][1])
    dp[u][1] += max(dp[v][0], dp[v][1])

  return


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