#P9210. 蓬莱「凯风快晴 −富士火山−」
蓬莱「凯风快晴 −富士火山−」
Background
Mount Fuji, called “the sacred mountain” by locals, is a dormant volcano. Its most recent eruption was years ago.
If you throw the elixir of immortality into such a mountain, it would probably erupt immediately. This explains why Tsukuyomi Iwakasa (Yueyanli) eventually disobeyed orders.
Problem Description
A “mountain” has a shape that is narrow at the top and wide at the bottom. Can we find a similar structure in a “tree”?
You are given a rooted tree of size with root . You need to find the largest induced subtree whose widths are monotonically non-decreasing:
- Let this induced subtree be , and it has levels.
- Define the depth of the root of to be , and compute the depth of each node in . Then define the width of level in as “the number of nodes with depth ”.
- You need to make monotonically non-decreasing, i.e., .
Let the vertex set and edge set of the original tree be . An induced subtree is a connected component of the original tree: its vertex set is , and its edge set contains all edges in whose both endpoints are in . The root of an induced subtree is the node among all its nodes that has the smallest depth in the original tree. itself can also be regarded as an induced subtree of itself.

As shown in the figure, the green region and the orange region are induced subtrees of the original tree. Their roots are and , respectively.
Note: The definition of an induced subtree is slightly different from the definition of a subtree. Please do not confuse the two.
Find the maximum size of an induced subtree that satisfies the condition.
Input Format
The first line contains a positive integer , the size of the whole tree.
The next lines each contain two integers , describing an edge in the tree.
Output Format
Output one line containing one integer, the maximum size of an induced subtree that satisfies the condition.
10
1 2
2 3
3 4
3 5
2 6
6 7
1 8
8 9
8 10
9
17
1 2
2 3
3 4
4 5
4 6
3 7
7 8
7 9
7 10
2 11
2 12
1 13
13 14
14 15
14 16
13 17
16
Hint
Sample Explanation

As shown in the figure, the gray nodes are the induced subtrees chosen in the two samples.
- In sample , the induced subtree found has widths for each level.
- In sample , the induced subtree found has widths for each level.
Constraints and Conventions
For all testdata, .
Translated by ChatGPT 5