結果

問題 No.763 Noelちゃんと木遊び
ユーザー 👑 H20H20
提出日時 2023-05-01 17:26:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 478 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 228,480 KB
最終ジャッジ日時 2024-04-30 17:54:42
合計ジャッジ時間 6,737 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 392 ms
228,480 KB
testcase_01 AC 164 ms
87,220 KB
testcase_02 AC 267 ms
101,032 KB
testcase_03 AC 204 ms
92,884 KB
testcase_04 AC 178 ms
88,664 KB
testcase_05 AC 199 ms
92,584 KB
testcase_06 AC 319 ms
106,204 KB
testcase_07 AC 306 ms
105,176 KB
testcase_08 AC 210 ms
94,208 KB
testcase_09 AC 166 ms
88,284 KB
testcase_10 AC 126 ms
81,444 KB
testcase_11 AC 308 ms
107,088 KB
testcase_12 AC 283 ms
102,908 KB
testcase_13 AC 279 ms
102,376 KB
testcase_14 AC 259 ms
100,088 KB
testcase_15 AC 208 ms
92,840 KB
testcase_16 AC 113 ms
80,284 KB
testcase_17 AC 205 ms
92,916 KB
testcase_18 AC 309 ms
106,572 KB
testcase_19 AC 298 ms
103,256 KB
testcase_20 AC 296 ms
103,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N-1)]
L = [[] for _ in range(N)]
for a,b in AB:
    L[a-1].append(b-1)
    L[b-1].append(a-1)
#木の数
DP = [[0]*2 for _ in range(N)]
def dfs(i,p):
    for l in L[i]:
        if l !=p:
            dfs(l,i)
    for l in L[i]:
        if l !=p:
            DP[i][0]+=max(DP[l][0]-1,DP[l][1])
            DP[i][1]+=max(DP[l])
    DP[i][0]+=1
dfs(0,-1)
print(max(DP[0]))
0