A10602 | Subordinates
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ workers in a company, each of them has a unique id from $1$ to $n$ . Exaclty one of them is a chief, his id is $s$ . Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.
Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.
输入格式
The first line contains two positive integers $n$ and $s$ ( $1<=n<=2·10^{5}$ , $1<=s<=n$ ) — the number of workers and the id of the chief.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $0<=a_{i}<=n-1$ ), where $a_{i}$ is the number of superiors (not only immediate) the worker with id $i$ reported about.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $0<=a_{i}<=n-1$ ), where $a_{i}$ is the number of superiors (not only immediate) the worker with id $i$ reported about.
输出格式
Print the minimum number of workers that could make a mistake.
输入输出样例
输入 #1
3 2 2 0 2
输出 #1
1
输入 #2
5 3 1 0 0 4 1
输出 #2
2
In the first example it is possible that only the first worker made a mistake. Then:
- the immediate superior of the first worker is the second worker,
- the immediate superior of the third worker is the first worker,
- the second worker is the chief.
- the immediate superior of the first worker is the second worker,
- the immediate superior of the third worker is the first worker,
- the second worker is the chief.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted