Independent Set (Max)
Time limit1sMemory limit2048 MB
Given a tree, find the maximum of (set size) times (minimum edges connecting the set) over all non-empty sets of pairwise non-adjacent nodes.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, DFS
- Solved
- No attempts yet
Problem
You are given a tree of nodes (numbered from to ). The edges are numbered from to . Edge connects node and .
A non-empty set of nodes is independent if no two nodes in the set are adjacent. The following illustration shows sets that are independent and sets that are not. The nodes colored in red are the members of the set.

The score of an independent set is the product of:
- the number of nodes in the set, and
- the minimum number of edges needed to keep all nodes in the set connected.
The following illustration shows how to calculate the score of an independent set. The set has nodes. The minimum number of edges needed to connect them is , shown in red. The score of this set is .

A set with only node has a score of .
Find the maximum score over all non-empty independent sets in the tree.
Input
The first line contains an integer (). Each of the next lines contains two integers and (). The input edges form a tree.
Output
Print a single integer, the maximum score over all non-empty independent sets in the tree.