Problem G. Problem G. Depth-First Search
时间限制 5000 ms
内存限制 256 MB
Kazari is learning
depth-first search. More precisely, she is doing an experiment about it.
Consider an unrooted tree with $n$ vertices and an empty array called $A$.
She randomly chooses a vertex $s$ as root and starts from $s$ to walk around, following the rules below.
* When she enters a vertex $x$ for the first time, she append $x$ to $A$ at once.
* If some adjacent vertex has not been visited, she randomly chooses one and walks into it.
* If all adjacent vertices have been visited,
* If she is at root, the experiment is done.
* If she is not at root, she walks into the vertex which is the most nearest to root.
Among all possible arrays that $A$ is likely to be finally, Kazari wishes to count how many of them is lexicographically smaller than the given array $B$. Since the answer is too large, print it modulo $10 ^ 9 + 7$.
输入数据
输出数据
For each test case, print a non-negative integer denoting the answer modulo $10 ^ 9 + 7$.
样例输入
复制
2
5
2 1 3 5 4
1 2
2 3
2 4
4 5
6
6 4 5 3 2 1
1 2
2 3
3 4
4 5
5 6
样例输出
$ Mathjax font initiator $