← 返回 snowflake 的题目列表Delete nodes from a tree to maximize remaining depth
类型:online_judge
Problem: Delete nodes in a rooted tree to maximize the remaining maximum depth
You are given an undirected tree with n nodes rooted at node 1. You may delete any number of nodes (possibly none). Deleting a node removes all incident edges. After deletions, the remaining nodes must still contain the root 1 and the remaining graph must be connected (i.e., still a rooted tree).
Output the maximum possible maximum depth (maximum number of edges from root to any remaining node) after such deletions.
Input
n
n-1 edges u v
Output
One integer: the maximum achievable depth.
Constraints
1 ≤ n ≤ 2e5
Note
You must keep the root and maintain connectivity of remaining nodes.
Examples
See tests below.
Example
Input
5
1 2
1 3
3 4
4 5
Output
3