5226: Road Improvement

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:0

题目描述

D. Road Improvement
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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).
Input
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≤pii-1) − the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i.
Output
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.
Examples
Input
3
1 1
Output
4 3 3
Input
5
1 2 3 4
Output
5 8 9 8 5

输入样例 复制


输出样例 复制