当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6338:Problem G. Depth-First Search

题目描述
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$.
输入解释
The first line of the input contains an integer $T$ denoting the number of test cases.
Each test case starts with a positive integer $n$ $(\sum{n} \le 10 ^ 6)$, denoting the number of vertices.
The second line contains $n$ integers $B_1, B_2, ..., B_n$ $(1 \le B_i \le n, \forall i \neq j, B_i \neq B_j)$.
Each of next $n - 1$ lines contains two integers $u, v$, representing an edge $(u, v)$ on the tree.
输出解释
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
输出样例
3
9
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6338

最后修改于 2020-10-25T23:30:25+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 262144/262144K(Java/Others)