A11120 | Nikita and game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Nikita plays a new computer game. There are $m$ levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class $y_{i}$ (and $y_{i}$ is called parent-class for this new class). Thus, the classes form a tree. Initially there is only one class with index $1$ .
Changing the class to its neighbour (child-class or parent-class) in the tree costs $1$ coin. You can not change the class back. The cost of changing the class $a$ to the class $b$ is equal to the total cost of class changes on the path from $a$ to $b$ in the class tree.
Suppose that at $i$ -th level the maximum cost of changing one class to another is $x$ . For each level output the number of classes such that for each of these classes there exists some other class $y$ , and the distance from this class to $y$ is exactly $x$ .
Changing the class to its neighbour (child-class or parent-class) in the tree costs $1$ coin. You can not change the class back. The cost of changing the class $a$ to the class $b$ is equal to the total cost of class changes on the path from $a$ to $b$ in the class tree.
Suppose that at $i$ -th level the maximum cost of changing one class to another is $x$ . For each level output the number of classes such that for each of these classes there exists some other class $y$ , and the distance from this class to $y$ is exactly $x$ .
输入格式
First line contains one integer number $m$ — number of queries ( $1<=m<=3·10^{5}$ ).
Next $m$ lines contain description of queries. $i$ -th line ( $1<=i<=m$ ) describes the $i$ -th level and contains an integer $y_{i}$ — the index of the parent-class of class with index $i+1$ ( $1<=y_{i}<=i$ ).
Next $m$ lines contain description of queries. $i$ -th line ( $1<=i<=m$ ) describes the $i$ -th level and contains an integer $y_{i}$ — the index of the parent-class of class with index $i+1$ ( $1<=y_{i}<=i$ ).
输出格式
Suppose that at $i$ -th level the maximum cost of changing one class to another is $x$ . For each level output the number of classes such that for each of these classes there exists some other class $y$ , and the distance from this class to $y$ is exactly $x$ .
输入输出样例
输入 #1
4 1 1 2 1
输出 #1
2 2 2 3
输入 #2
4 1 1 2 3
输出 #2
2 2 2 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted