cswork / OA打开练习工作台

SafetyKitOA #3

Best Sum Downward Tree Path

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)树上路径动规入门

For a tree with n nodes rooted at node 0, each node i has a value given by values[i]. Determine the maximum sum of values along any path that starts at a node and only goes downward in the tree.

Consider only paths of the form u_1 -> u_2 -> ... -> u_k where each u_{i+1} is a child of u_i. The path can start at any node, not necessarily the root, and includes at least the start node.

Function signature: int bestSumDownwardTreePath(int parent[n], int values[n]), with parent[0] = -1.