Number of Tree Automorphisms
Time limit5sMemory limit128 MB
Count the automorphisms of a tree modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Tree, DFS, Hash map, Combinatorics
- Solved
- No attempts yet
Problem
A tree is an undirected graph in which any two nodes are connected by at most one simple path (a path that does not repeat nodes).
Consider a tree with nodes numbered from to . Let be a permutation of the tree's nodes, that is, a bijection . The permutation is an automorphism if, for every pair of nodes and , the nodes and are joined by an edge if and only if and are joined by an edge.
Count the number of distinct automorphisms of a given tree, modulo .
Input
The first line contains an integer (), the number of nodes in the tree. Each of the next lines contains two integers and () describing an edge between nodes and .
Output
Print a single integer: the number of distinct automorphisms of the given tree, taken modulo .
Hint

The tree above has automorphisms. Three of them are:
- for (the identity)
- for , with and
- , , , , ,