QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#10389. Automorphisms [B]

Statistics

A tree is an undirected graph in which any two nodes are connected with at most one simple path, that is, a path without repeating nodes.

Consider a tree with $n$ nodes numbered $1$ through $n$. Let $P$ be a permutation of the set of nodes of the tree, that is, a one-to-one function (injection) $P : \{1, 2, \ldots, n\} \to \{1, 2, \ldots, n\}$. The permutation P is called an automorphism if for any two nodes $u$, $v$ of the tree, the nodes $P(u)$ and $P(v)$ are connected with an edge if and only if $u$ and $v$ are connected with an edge.

We would like to know what is the number of different automorphisms of a given tree modulo $1\,000\,000\,007$.

Input Format

The first line of the standard input contains an integer $n$ ($1 ≤ n ≤ 500,000$): the number of nodes of the tree. Each of the following n-1 lines contains two integers $u_{i}$ and $v_{i}$ ($1 ≤ u_{i} < v_{i} ≤ n$) that represent an edge connecting the nodes $u_{i}$ and $v_{i}$.

Output Format

The first and only line of the standard output should contain one integer: the number of different automorphisms of the given tree modulo $1\,000\,000\,007$.

Example

Input

6
1 3
2 3
3 4
4 5
4 6

Output

8

Notes

This tree has 8 automorphisms, in particular, the following three:

  • $p(i) = i$ for $i = 1, 2, 3, 4, 5, 6$

  • $q(i) = i$ for $i = 1, 2, 3, 4, q(5) = 6, q(6) = 5$

  • $r(1) = 6, r(2) = 5, r(3) = 4, r(4) = 3, r(5) = 1, r(6) = 2$.

problem_10389_1.gif
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.