#5195. Problem 3. Circus
Problem 3. Circus
Problem 3. Circus
USACO 2020 US Open Contest, Platinum
The cows of Farmer John's Circus () are preparing their upcoming acts. The acts all take place on a tree with vertices labeled . The "starting state" of an act is defined by a number and an assignment of cows to the vertices of the tree, so that no two cows are located at the same vertex.
In an act, the cows make an arbitrarily large number of "moves." In a move, a single cow moves from her current vertex to an unoccupied adjacent vertex. Two starting states are said to be equivalent if one may be reached from the other by some sequence of moves.
For each , help the cows determine the number of equivalence classes of starting states: that is, the maximum number of starting states they can pick such that no two are equivalent. Since these numbers may be very large, output their remainders modulo .
INPUT FORMAT (file circus.in):
Line contains .
Lines each contain two integers and denoting an edge between and in the tree.
OUTPUT FORMAT (file circus.out):
For each the -th line of output should contain the answer for modulo .
SAMPLE INPUT:
5 1 2 2 3 3 4 3 5
SAMPLE OUTPUT:
1 1 3 24 120
For and any two states can be transformed into one another.
Now consider , and let denote the location of cow . The state is equivalent to the states and However, it is not equivalent to the state
SAMPLE INPUT:
8 1 3 2 3 3 4 4 5 5 6 6 7 6 8
SAMPLE OUTPUT:
1 1 1 6 30 180 5040 40320
SCORING: Test cases 3-4 satisfy Test cases 5-7 satisfy Test cases 8-10 satisfy and the tree forms a "star;" at most one vertex has degree greater than two.Test cases 11-15 satisfy .Test cases 16-20 satisfy no additional constraints.
Problem credits: Dhruv Rohatgi