Justified Jungle
Time limit6sMemory limit512 MB
Given a tree with n nodes, find every k such that removing exactly k edges leaves a forest whose connected components all have the same size.
- Level
Medium7 of 10
- Topics
- Tree, DFS, Number theory, Math
- Solved
- No attempts yet
Problem
A tree is a graph with nodes and undirected edges in which every two nodes are connected by exactly one path. A forest is a graph made of one or more trees. In other words, a graph is a forest when every connected component is a tree. A forest is justified when all of its connected components hold the same number of nodes.
You are given a tree with nodes. Find every positive integer such that erasing exactly edges from leaves a justified forest. Erasing an edge never erases a node. In particular, erasing all edges of leaves a justified forest of one-node components.
Input
The first line contains the number of nodes of . ()
The -th of the next lines contains two different integers and , the endpoints of the -th edge. ()
Output
On the first line print every wanted in increasing order. Separate the numbers with single spaces.
Hint

The figures show the justified forests obtained by erasing 1, 3 and 7 edges from the tree in the sample input.