CF729E.Subordinates
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一家公司中有 n 名员工,每名员工都有一个从 1 到 n 的唯一编号。其中恰好有一名是主管(chief),其编号为 s。除主管外,每名员工都恰好有一名直接上级(immediate superior)。
公司曾要求每名员工报告自己有多少名上级(不仅限于直接上级)。一名员工的所有上级包括:他的直接上级、他直接上级的直接上级,依此类推。例如,若公司共有三名员工,其中第 1 号员工是主管,第 2 号员工的直接上级是第 1 号,第 3 号员工的直接上级是第 2 号,则第 3 号员工有两名上级——其中一名是直接上级,另一名不是。主管是除他自己以外所有员工的上级。
部分员工因匆忙而给出了错误答案。你需要求出可能出错的员工人数的最小值。
输入格式
The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 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.
第一行包含两个正整数 n 和 s(1 ≤ n ≤ 2⋅105,1 ≤ s ≤ n)—— 分别表示工人的数量以及主管的编号。
第二行包含 n 个整数 a1, a2, ..., an(0 ≤ ai ≤ n − 1),其中 ai 表示编号为 i 的工人所报告的其上级(不仅限于直接上级)的数量。
输出格式
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.
在第一个例子中,可能只有第一位工人犯了错误。此时:
- 第一位工人的直接上级是第二位工人,
- 第三位工人的直接上级是第一位工人,
- 第二位工人是主管。
输入解题思路,AI测评打分。不知道怎么写?