結果

問題 No.763 Noelちゃんと木遊び
ユーザー neko0774neko0774
提出日時 2023-01-30 01:15:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 195,088 KB
最終ジャッジ日時 2023-09-12 06:46:56
合計ジャッジ時間 8,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 436 ms
195,088 KB
testcase_01 AC 232 ms
86,420 KB
testcase_02 AC 363 ms
97,472 KB
testcase_03 AC 277 ms
90,512 KB
testcase_04 AC 247 ms
87,624 KB
testcase_05 AC 283 ms
90,360 KB
testcase_06 AC 403 ms
99,152 KB
testcase_07 AC 395 ms
98,504 KB
testcase_08 AC 299 ms
91,564 KB
testcase_09 AC 251 ms
87,548 KB
testcase_10 AC 175 ms
82,276 KB
testcase_11 AC 410 ms
100,252 KB
testcase_12 AC 372 ms
98,100 KB
testcase_13 AC 365 ms
97,892 KB
testcase_14 AC 334 ms
95,656 KB
testcase_15 AC 279 ms
90,932 KB
testcase_16 AC 168 ms
80,892 KB
testcase_17 AC 291 ms
90,508 KB
testcase_18 AC 408 ms
100,096 KB
testcase_19 AC 385 ms
98,440 KB
testcase_20 AC 383 ms
98,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def main():
    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)]
    #o exist
    #1 not exist
    seen = [0]*N
    def dfs(x):
        seen[x] = 1
        for nx in G[x]:
            if seen[nx]: continue
            dfs(nx)
            dp[x][0] += max(dp[nx])
            dp[x][1] += max(dp[nx][0]+1, dp[nx][1])
    dfs(0)
    print(max(dp[0][0]+1, dp[0][1]))
main()
0