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

建议使用的浏览器:

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

5647:DZY Loves Connecting

题目描述
DZY has an unrooted tree consisting of $n$ nodes labeled from $1$ to $n$.

DZY likes connected sets on the tree. A connected set $S$ is a set of nodes, such that every two nodes $u,v$ in $S$ can be connected by a path on the tree, and the path should only contain nodes from $S$. Obviously, a set consisting of a single node is also considered a connected set.

The size of a connected set is defined by the number of nodes which it contains. DZY wants to know the sum of the sizes of all the connected sets. Can you help him count it?

The answer may be large. Please output modulo $10^9 + 7$.
输入解释
First line contains $t$ denoting the number of testcases.
$t$ testcases follow. In each testcase, first line contains $n$. In lines $2 \sim n$, $i$th line contains $p_i$, meaning there is an edge between node $i$ and node $p_i$. ($1\le p_i \le i-1,2\le i\le n$)

($n\ge 1$, sum of $n$ in all testcases does not exceed $200000$)
输出解释
Output one line for each testcase, modulo $10^9 + 7$.
输入样例
2
1
5
1
2
2
3
输出样例
1
42

提示
In the second sample, the 4 edges are (1,2),(2,3),(2,4),(3,5). All the connected sets are {1},{2},{3},{4},{5},{1,2},{2,3},{2,4},{3,5},{1,2,3},{1,2,4},{2,3,4},{2,3,5},{1,2,3,4},{1,2,3,5},{2,3,4,5},{1,2,3,4,5}.

If you need a larger stack size, 
please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5647

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

共提交 0

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