Codeforces Round 302 (Div. 1)
D
Road Improvement
Codeforces
2300
原题
← CE →
翻译中…

The country has $*n*$ cities and $*n* - 1$ bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from $1$ to $*n*$ inclusive.

翻译中…

All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city $*x*$ to any other city contains at most one bad road.

翻译中…

Your task is — for every possible $*x*$ determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo $1 000 000 007$ ($10^{9} + 7$).

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($2 ≤ *n* ≤ 2·10^{5}$) — the number of cities in the country. Next line contains $*n* - 1$ positive integers $*p*_{2}, *p*_{3}, *p*_{4}, ..., *p*_{*n*}$ ($1 ≤ *p*_{*i*} ≤ *i* - 1$) — the description of the roads in the country. Number $*p*_{*i*}$ means that the country has a road connecting city $*p*_{*i*}$ and city $*i*$.

翻译中…

Output

翻译中…

Print $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$, where $*a*_{*i*}$ is the sought number of ways to improve the quality of the roads modulo $1 000 000 007$ ($10^{9} + 7$), if the capital of the country is at city number $*i*$.

翻译中…

样例

Input #1
3
1 1
Output #1
4 3 3
InputCopy OutputCopy
Input #2
5
1 2 3 4
Output #2
5 8 9 8 5
InputCopy OutputCopy
题目信息
题号
543D
时间限制
2 s
内存限制
256 MB
标签
动态规划
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。