This page is still under construction.

Parts of this page are still being built. What you see may change.

Number of Tree Automorphisms

Time limit5sMemory limit128 MB

Summary
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 nn nodes numbered from 11 to nn. Let PP be a permutation of the tree's nodes, that is, a bijection P:{1,2,…,n}→{1,2,…,n}P : \{1, 2, \ldots, n\} \to \{1, 2, \ldots, n\}. The permutation PP is an automorphism if, for every pair of nodes uu and vv, the nodes P(u)P(u) and P(v)P(v) are joined by an edge if and only if uu and vv are joined by an edge.

Count the number of distinct automorphisms of a given tree, modulo 1,000,000,0071{,}000{,}000{,}007.

Input

The first line contains an integer nn (1≤n≤500,0001 \le n \le 500{,}000), the number of nodes in the tree. Each of the next n−1n - 1 lines contains two integers uiu_i and viv_i (1≤ui<vi≤n1 \le u_i < v_i \le n) describing an edge between nodes uiu_i and viv_i.

Output

Print a single integer: the number of distinct automorphisms of the given tree, taken modulo 1,000,000,0071{,}000{,}000{,}007.

Hint

The tree above has 88 automorphisms. Three of them are:

  • p(i)=ip(i) = i for i=1,2,3,4,5,6i = 1, 2, 3, 4, 5, 6 (the identity)
  • q(i)=iq(i) = i for i=1,2,3,4i = 1, 2, 3, 4, with q(5)=6q(5) = 6 and q(6)=5q(6) = 5
  • r(1)=6r(1) = 6, r(2)=5r(2) = 5, r(3)=4r(3) = 4, r(4)=3r(4) = 3, r(5)=1r(5) = 1, r(6)=2r(6) = 2

Examples1

  1. Example 1

    Input
    6
    1 3
    2 3
    3 4
    4 5
    4 6
    
    Expected output
    8