This page is still under construction.

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

Ranking

Time limit2sMemory limit512 MB

Summary
Given N-1 comparisons where tower a is taller than b, and each tower loses to a taller tower at most once, count the possible total order tables consistent with these facts.
Level

Medium7 of 10

Topics
Combinatorics, Tree, Dynamic programming, Graph
Solved
No attempts yet

Problem

In the town where Ikuta lives there are NN towers. Each tower is given a distinct number from 0 to N−1N-1, and the tower numbered ii is called tower ii. Curious Ikuta took an interest in the heights of the NN towers and decided to build a table TT that describes their order. TT has N×NN \times N elements, and each element Ti,j(0≤i,j≤N−1)T_{i, j} (0 \leq i, j \leq N - 1) is defined as follows.

  • Ti,j=−1  ⟺  T_{i, j} = -1 \iff the height of tower ii is less than the height of tower jj

  • Ti,j=0  ⟺  T_{i, j} = 0 \iff the height of tower ii equals the height of tower jj

  • Ti,j=1  ⟺  T_{i, j} = 1 \iff the height of tower ii is greater than the height of tower jj

To build the table TT, Ikuta repeatedly chose two towers and compared their heights, N−1N-1 times in total.

The following is known about Ikuta's survey.

  • If tower aia_{i} and tower bib_{i} were chosen in the ii-th comparison (1≤i≤N−1)(1 \leq i \leq N - 1), then the height of tower aia_{i} was greater than the height of tower bib_{i}. That is, Tai,bi=1T_{a_{i}, b_{i}} = 1 and Tbi,ai=−1T_{b_{i}, a_{i}} = -1.

  • Each tower was compared with a taller tower at most once.

Unfortunately, the information from Ikuta's survey alone does not always determine the contents of table TT uniquely. When TT does not contradict Ikuta's survey and there exists a combination of tower heights for which TT is defined, call TT a correct table. Compute how many correct tables are possible and tell Ikuta.

Note that the two compared towers have different heights, but not all tower heights are necessarily different.

Input

The input is given in the following format.

NN

a1a_{1} b1b_{1}

...

aN−1a_{N-1} bN−1b_{N-1}

NN represents the number of towers. aia_{i}, bib_{i} (1≤i≤N−11 \leq i \leq N - 1) mean that tower aia_{i} is taller than tower bib_{i}.

Output

Output the number of possible correct tables TT modulo 1,000,000,007.

Constraints

Each variable in the input satisfies the following conditions.

  • 1≤N≤2001 \leq N \leq 200

  • 0≤ai,bi<N0 \leq a_{i}, b_{i} < N

  • ai≠bia_{i} \neq b_{i}

  • Different towers may have the same height.

  • Ikuta's survey results themselves are consistent, and at least one table TT exists that does not contradict the survey results.

Examples4

  1. Example 1

    Input
    3
    0 1
    1 2
    
    Expected output
    1
    
  2. Example 2

    Input
    3
    0 1
    0 2
    
    Expected output
    3
    
  3. Example 3

    Input
    1
    
    Expected output
    1
    
  4. Example 4

    Input
    7
    0 1
    1 2
    2 3
    3 4
    0 5
    0 6
    
    Expected output
    91