CF543D.Road Improvement

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 1 000 000 007 (109 + 7).

该国有 nn 座城市和 n−1n-1 条双向道路,仅沿道路行走时,从任意一座城市均可到达其他任意一座城市。城市编号为 11 到 nn(含端点)。

所有道路初始均为劣质道路,但政府希望改善其中部分道路的质量。我们定义:若从位于城市 xx 的首都到任意其他城市的路径中至多包含一条劣质道路,则市民对道路改善感到满意。

你的任务是:对每个可能的 xx,计算满足市民条件的道路质量改善方案数。由于结果可能非常大,你需要对每个答案模 1 000 000 0071\,000\,000\,007(即 109+710^9 + 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 _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.

输入的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5)—— 表示该国城市的数量。
第二行包含 n−1n-1 个正整数 p2, p3, p4, …, pnp_2,\ p_3,\ p_4,\ \dots,\ p_n(1≤pi≤i−11 \leq p_i \leq i-1)—— 描述该国的道路。其中,数字 pip_i 表示该国有一条连接城市 pip_i 和城市 ii 的道路。

输出格式

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 1 000 000 007 (109 + 7), if the capital of the country is at city number i.

输出 nn 个整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n,其中 aia_i 表示当国家首都位于第 ii 号城市时,提升道路质量的方案数(对 1 000 000 0071\,000\,000\,007(即 109+710^9 + 7)取模)所求得的数值。

输入输出样例

  • 输入#1

    3
    1 1

    输出#1

    4 3 3
  • 输入#2

    5
    1 2 3 4

    输出#2

    5 8 9 8 5

输入解题思路,AI测评打分。不知道怎么写?

首页