A9948 | Road Improvement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ ( $10^{9}+7$ ).
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$ ( $10^{9}+7$ ).
输入格式
The first line of the input contains a single integer $n$ ( $2<=n<=2·10^{5}$ ) — 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$ .
输出格式
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 $1000000007$ ( $10^{9}+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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted