E. Subordinates
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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 a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.

Output

Print the minimum number of workers that could make a mistake.

Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
Note

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.

题意:给你n个人,每个人只有一个大佬,大佬可能有大大佬,但是只有一个boss,boss没有大佬;

   告诉你哪个是boss,和每个人大佬,大大佬,大大大佬。。。的个数,问最小几个人是错误的;

思路:如果当前深度为空,用最深的那个堵上,答案加一;

#include<bits/stdc++.h>
using namespace std;
const int N=,mod=1e9+,MOD=;
int a[N],flag[N];
int main()
{
int n,s;
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
flag[a[i]]++;
}
int now=,ans=,z=n;
if(a[s]!=)
ans+=flag[]+,now=flag[],z-=flag[]+,flag[a[s]]--;
else
ans+=flag[]-,now=flag[]-,z-=flag[];
for(int i=;i<n;i++)
{
if(z<=)break;
if(!flag[i])
{
ans++;
if(now)
{
ans--;
now--;
}
else
{
z--;
} }
else
{
z-=flag[i];
}
}
printf("%d\n",ans);
return ;
}

Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心的更多相关文章

  1. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  2. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  3. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  8. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. SQL Server 数据库中关于死锁的分析

    SQL Server数据库发生死锁时不会像Oracle那样自动生成一个跟踪文件.有时可以在[管理]->[当前活动] 里看到阻塞信息(有时SQL Server企业管理器会因为锁太多而没有响应). ...

  2. lz: linux ls 变种 只显示大小和名称(包括目录)

    本次输入法使用: 手心输入法 for Mac 1.0版 测试环境为:Ubuntu 14.14.2 LTS updates 测试时间为:2015年5月28日,感觉死亡将至的夜晚,独自一人坐在一个角落,戴 ...

  3. 【原创】纯干货,Spring-data-jpa详解,全方位介绍。

    本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...

  4. 测试驱动开发神器框架Mockito

    作为菜鸟的我,以前没接触过Mock类型的框架,比如说要测试action层,我总是从action层调用service再调用dao访问数据库,这种方式从原则上来说是无疑是非常正确的,在没用mock框架之前 ...

  5. asp.net中调用javascript自定义函数的方法(包括引入JavaScript文件)总结

    通常javascript代码可以与HTML标签一起直接放在前 端页面中,但如果JS代码多的话一方面不利于维护,另一方面也对搜索引擎不友好,因为页面因此而变得臃肿:所以一般有良好开发习惯的程序员都会把 ...

  6. css 样式设计(一)( 在线150个例子 | 背景 | 文本 | 字体 | 链接 | 列表 | 表格 | 盒模型 | 边框 | 轮廓 | 边距 | 填充 |分组和嵌套 | 尺寸 | 定位 | 浮动 |对齐 )

    一.css在线150个例子 http://www.w3cschool.cc/css/css-examples.html 二.背景图片水平方向重复 : body { background-image:u ...

  7. 每日一九度之 题目1041:Simple Sorting

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4883 解决:1860 题目描述: You are given an unsorted array of integer numbers. ...

  8. c#读取Excel的列名问题

    在修改c#读取Excel的时候,遇到了一些小问题,总结下,希望别人不用再浪费时间 读取excel的时候,如果是空行就不读取? SELECT * FROM [DB_ESTATE$] where F2&l ...

  9. Discuz! 6.x/7.x 全局变量防御绕过导致命令执行

    https://www.secpulse.com/archives/2338.html 模拟register_globals功能的代码,在GPC为off时会调用addslashes()函数处理变量值, ...

  10. winform中利用反射实现泛型数据访问对象基类(2)

    在1的基础上做了一点改进 参数化处理 看上去更简洁 无主键情况下 update 方法需要改进 insert delete没有问题  /// <summary>     /// DAO基类 ...