Delegation (Gold)
Time limit2sMemory limit512 MB
Given a tree with N pastures, decide for each K from 1 to N-1 whether its edges can be split into paths that each have exactly K edges.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Divide and conquer, Number theory
- Solved
- No attempts yet
Problem
Farmer John's farm consists of pastures () connected by roads, so that any pasture is reachable from any other pasture. That is, the farm is a tree. After 28 years of dealing with the tricky algorithmic problems that arise from trees, FJ has decided that a tree-shaped farm is too complex. He believes algorithmic problems are simpler on paths.
So he plans to partition the set of roads into several paths and delegate each path to a farm hand. To avoid contention, every path must have the same length. For which lengths does such a partition exist?
For each , determine whether the roads can be partitioned into paths of length exactly .
Input
The first line contains a single integer . Each of the next lines contains two integers and , describing an edge between pastures and . Both and are in the range to .
Output
Output a bit string of length . The th bit from the left is 1 if the edges can be partitioned into paths of length exactly , and 0 otherwise.
Hint
The tree can be partitioned into paths of length for . For , one possible set of paths is 13-12-11-8, 10-9-8-6, 7-6-2-3, 5-4-2-1.