测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A9948. Road Improvement

编程题 普及/提高-

题目描述

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 $1000000007$ ( $10^{9}+7$ ).

输入格式

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$ .

输出格式

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 $1000000007$ ( $10^{9}+7$ ), if the capital of the country is at city number $i$ .

输入输出样例

输入 #1
3
1 1
输出 #1
4 3 3
输入 #2
5
1 2 3 4
输出 #2
5 8 9 8 5
上一题 去做题 下一题