結果

問題 No.763 Noelちゃんと木遊び
ユーザー torikuminotorikumino
提出日時 2018-12-14 10:18:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 516 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 11,800 KB
実行使用メモリ 61,180 KB
最終ジャッジ日時 2023-10-25 09:55:47
合計ジャッジ時間 10,800 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 AC 484 ms
24,232 KB
testcase_03 AC 323 ms
19,880 KB
testcase_04 AC 242 ms
17,152 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 582 ms
26,720 KB
testcase_08 AC 350 ms
20,300 KB
testcase_09 AC 237 ms
16,920 KB
testcase_10 AC 107 ms
12,756 KB
testcase_11 WA -
testcase_12 AC 551 ms
25,540 KB
testcase_13 WA -
testcase_14 AC 469 ms
23,760 KB
testcase_15 AC 322 ms
19,536 KB
testcase_16 WA -
testcase_17 AC 327 ms
19,836 KB
testcase_18 AC 600 ms
27,264 KB
testcase_19 AC 550 ms
25,868 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(sys.getrecursionlimit()*100)

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)

dp = [[-1]*n, [-1]*n]
def dfs(i, j, p):
    if dp[i][j] >= 0:
        return dp[i][j]
    dp[i][j] = 0
    for k in g[j]:
        if k == p:
            continue
        dp[i][j] += max(
            dfs(1, k, j)+1-i,
            dfs(0, k, j))
    return dp[i][j]

print(max(dfs(0, 0, 0), dfs(1, 0, 0))+1)
0