結果

問題 No.763 Noelちゃんと木遊び
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-02-02 15:50:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 192,288 KB
最終ジャッジ日時 2023-09-14 21:38:48
合計ジャッジ時間 9,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 440 ms
192,288 KB
testcase_01 AC 260 ms
89,468 KB
testcase_02 AC 356 ms
94,208 KB
testcase_03 AC 301 ms
91,232 KB
testcase_04 AC 273 ms
89,832 KB
testcase_05 AC 301 ms
91,232 KB
testcase_06 AC 385 ms
96,420 KB
testcase_07 AC 377 ms
95,872 KB
testcase_08 AC 306 ms
91,364 KB
testcase_09 AC 273 ms
89,604 KB
testcase_10 AC 227 ms
86,764 KB
testcase_11 AC 392 ms
96,996 KB
testcase_12 AC 372 ms
95,072 KB
testcase_13 AC 361 ms
95,356 KB
testcase_14 AC 347 ms
93,936 KB
testcase_15 AC 295 ms
91,696 KB
testcase_16 AC 219 ms
86,888 KB
testcase_17 AC 308 ms
91,584 KB
testcase_18 AC 388 ms
97,312 KB
testcase_19 AC 376 ms
95,752 KB
testcase_20 AC 363 ms
95,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from typing import List

sys.setrecursionlimit(int(1e9))
input = lambda: sys.stdin.readline().rstrip("\r\n")


if __name__ == "__main__":
    n = int(input())
    adjList = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int, input().split())
        u, v = u - 1, v - 1
        adjList[u].append(v)
        adjList[v].append(u)

    def dfs(cur: int, pre: int) -> List[int]:
        res = [1, 0]  # 不删除/删除当前节点后的最大连通分量数
        for next in adjList[cur]:
            if next == pre:
                continue
            nextRes = dfs(next, cur)
            res[0] += max(nextRes[0] - 1, nextRes[1])
            res[1] += max(nextRes[0], nextRes[1])
        return res

    res = dfs(0, -1)
    print(max(res))
0