結果

問題 No.763 Noelちゃんと木遊び
ユーザー H3PO4H3PO4
提出日時 2021-01-16 09:13:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 47,668 KB
最終ジャッジ日時 2023-08-18 05:42:50
合計ジャッジ時間 10,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 463 ms
47,668 KB
testcase_01 AC 179 ms
13,688 KB
testcase_02 AC 430 ms
21,044 KB
testcase_03 AC 281 ms
17,000 KB
testcase_04 AC 207 ms
14,656 KB
testcase_05 AC 280 ms
16,724 KB
testcase_06 AC 530 ms
23,628 KB
testcase_07 AC 515 ms
23,120 KB
testcase_08 AC 290 ms
17,272 KB
testcase_09 AC 192 ms
14,488 KB
testcase_10 AC 84 ms
10,416 KB
testcase_11 AC 543 ms
23,980 KB
testcase_12 AC 464 ms
22,264 KB
testcase_13 AC 454 ms
22,028 KB
testcase_14 AC 407 ms
20,396 KB
testcase_15 AC 284 ms
16,744 KB
testcase_16 AC 58 ms
9,768 KB
testcase_17 AC 276 ms
16,812 KB
testcase_18 AC 529 ms
23,948 KB
testcase_19 AC 467 ms
22,484 KB
testcase_20 AC 471 ms
22,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 9)

N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = (int(x) - 1 for x in input().split())
    T[a].append(b)
    T[b].append(a)


def rec(v, parent):
    remove, leave = 0, 1
    for child in T[v]:
        if child == parent:
            continue
        remove_c, leave_c = rec(child, v)
        remove += max(remove_c, leave_c)
        leave += max(remove_c, leave_c - 1)
    return remove, leave


print(max(rec(0, -1)))
0