cswork / OA打开练习工作台

AmazonOA #266

Maximize Product of Sizes of Subtrees

估计困难可在线判题

考点(AI 标注)背包计数位运算

Given an undirected tree, delete at least one edge, and as many as you like, forming several connected components. Each component's size is its number of nodes; find the maximum product of all component sizes. There are no node weights, the answer is not taken modulo anything, and not cutting at all is not allowed. The original text of this page explicitly says one or more, and examples from another, conflicting problem page must not replace this page's rule.

输入格式

The first line contains n, followed by n−1 lines each containing u v; nodes are numbered 1..n and are guaranteed to form a tree. The original text had no numeric bounds; this site uses 2≤n≤2000, and the output is an exact integer that may exceed 64 bits.

输出格式

Output a single integer, the answer.

样例 1

输入:

5
1 2
2 3
3 4
4 5

输出:

6

样例 2

输入:

2
1 2

输出:

1

样例 3

输入:

6
1 2
1 3
1 4
1 5
1 6

输出:

5

样例说明

The answers are 6, 1 and 5. A star cannot be split arbitrarily into two 3-node components as in integer partitioning; a two-node tree must be cut, giving 1.