CF543D.Road Improvement

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The country has nn cities and n1n-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 11 to nn 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 xx to any other city contains at most one bad road.

Your task is — for every possible xx 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 10000000071000000007 ( 109+710^{9}+7 ).

输入格式

The first line of the input contains a single integer nn ( 2<=n<=21052<=n<=2·10^{5} ) — the number of cities in the country. Next line contains n1n-1 positive integers p2,p3,p4,...,pnp_{2},p_{3},p_{4},...,p_{n} ( 1<=pi<=i11<=p_{i}<=i-1 ) — the description of the roads in the country. Number pip_{i} means that the country has a road connecting city pip_{i} and city ii .

输出格式

Print nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} , where aia_{i} is the sought number of ways to improve the quality of the roads modulo 10000000071000000007 ( 109+710^{9}+7 ), if the capital of the country is at city number ii .

输入输出样例

  • 输入#1

    3
    1 1
    

    输出#1

    4 3 3
  • 输入#2

    5
    1 2 3 4
    

    输出#2

    5 8 9 8 5
首页