結果

問題 No.763 Noelちゃんと木遊び
ユーザー neko0774neko0774
提出日時 2023-01-30 01:14:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 549 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 34,528 KB
最終ジャッジ日時 2023-09-12 06:45:03
合計ジャッジ時間 9,124 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 153 ms
16,896 KB
testcase_02 AC 371 ms
28,348 KB
testcase_03 AC 247 ms
21,988 KB
testcase_04 AC 171 ms
18,204 KB
testcase_05 AC 239 ms
21,568 KB
testcase_06 AC 474 ms
32,712 KB
testcase_07 AC 437 ms
31,700 KB
testcase_08 AC 249 ms
22,576 KB
testcase_09 AC 166 ms
17,760 KB
testcase_10 AC 74 ms
12,028 KB
testcase_11 AC 482 ms
33,324 KB
testcase_12 AC 407 ms
30,432 KB
testcase_13 AC 402 ms
29,784 KB
testcase_14 AC 356 ms
27,820 KB
testcase_15 AC 243 ms
21,864 KB
testcase_16 AC 53 ms
10,760 KB
testcase_17 AC 245 ms
21,984 KB
testcase_18 AC 474 ms
32,792 KB
testcase_19 AC 432 ms
30,664 KB
testcase_20 AC 430 ms
30,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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