atcoder#MUJINPC2017D. Oriented Tree

Oriented Tree

Score : 18001800 points

Problem Statement

There is a tree TT with NN vertices, numbered 11 through NN. For each 1iN11 \leq i \leq N - 1, the ii-th edge connects vertices aia_i and bib_i.

Snuke is constructing a directed graph TT' by arbitrarily assigning direction to each edge in TT. (There are 2N12^{N - 1} different ways to construct TT'.)

For a fixed TT', we will define d(s, t)d(s,\ t) for each 1s, tN1 \leq s,\ t \leq N, as follows:

  • d(s, t)=d(s,\ t) =(The number of edges that must be traversed against the assigned direction when traveling from vertex ss to vertex tt)

In particular, d(s, s)=0d(s,\ s) = 0 for each 1sN1 \leq s \leq N. Also note that, in general, d(s, t)d(t, s)d(s,\ t) \neq d(t,\ s).

We will further define DD as the following:

3d2f3f88e8fa23f065c04cd175c14ebf.png

Snuke is constructing TT' so that DD will be the minimum possible value. How many different ways are there to construct TT' so that DD will be the minimum possible value, modulo 109+710^9 + 7?

Constraints

  • 2N10002 \leq N \leq 1000
  • 1ai, biN1 \leq a_i,\ b_i \leq N
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

a2a_2 b2b_2

::

aN1a_{N - 1} bN1b_{N - 1}

Output

Print the number of the different ways to construct TT' so that DD will be the minimum possible value, modulo 109+710^9 + 7.

4
1 2
1 3
1 4
2

The minimum possible value for DD is 11. There are two ways to construct TT' to achieve this value, as shown in the following figure:

4
1 2
2 3
3 4
6

The minimum possible value for DD is 22. There are six ways to construct TT' to achieve this value, as shown in the following figure:

6
1 2
1 3
1 4
2 5
2 6
14
10
2 4
2 5
8 3
10 7
1 6
2 8
9 5
8 6
10 6
102