CF543D.Road Improvement
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ( 109+7 ).
输入格式
The first line of the input contains a single integer n ( 2<=n<=2⋅105 ) — the number of cities in the country. Next line contains n−1 positive integers p2,p3,p4,...,pn ( 1<=pi<=i−1 ) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i .
输出格式
Print n integers a1,a2,...,an , where ai is the sought number of ways to improve the quality of the roads modulo 1000000007 ( 109+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