July 12 - ADA Training
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 1 to any other city contains at most one bad road.
Determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As the answer can be large, print it modulo 1 000 000 007 (
109 + 7).
The first line contains a single integer n (2 ≤ n ≤ 2 *
105) — the number of cities in the country. Next line contains n - 1 positive integers
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 the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (
109 + 7).
3 1 1
6 1 2 2 1 5