301657: CF316B2. EKG
Memory Limit:256 MB
Time Limit:0 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
EKG
题意翻译
一家医院的挂号处,排起了一条长度为 $n$ 的队,这 $n$ 个人依次编号为 $1\sim n$ 一个人只会记得他前面的人的编号,而其中的某些人,已经忘记了前面人的编号。 给出 $n$ 和 $pos$ ,请求出编号为 $pos$ 的人在队伍中所有可能站的位置。 ### 输入格式 第一行两个整数 $n,pos$,分别表示人数和指定的人的编号。 第二行 $n$ 个数 $a_1,a_2 \dots a_n$,$a_i$表示第 $i$ 个人(编号为 $i$)前面的人的编号。 如果 $a_i=0$ 表示他不记得前面是谁了 数据保证每个人前后最多各只有一个人。 ### 输出格式 若干行,每行一个正整数表示编号为 $pos$ 的人可能站的位置 **说明与提示** $0 \le a_i \le n$ $1 \le n,pos \le 1000$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译题目描述
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another. (Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left. The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic. Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time... As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.输入输出格式
输入格式
The first line contains two integers $ n $ $ (1<=n<=10^{3}) $ and $ x $ $ (1<=x<=n) $ — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to $ n $ . The second line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ $ (0<=a_{i}<=n) $ — the number of the beaver followed by the $ i $ -th beaver. If $ a_{i}=0 $ , then the $ i $ -th beaver doesn't know who is should be in front of him. It is guaranteed that values $ a_{i} $ are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue. The input limits for scoring 30 points are (subproblem B1): - It is guaranteed that the number of zero elements $ a_{i} $ doesn't exceed $ 20 $ . The input limits for scoring 100 points are (subproblems B1+B2): - The number of zero elements $ a_{i} $ is arbitrary.
输出格式
Print all possible positions of the Smart Beaver in the line in the increasing order.
输入输出样例
输入样例 #1
6 1
2 0 4 0 6 0
输出样例 #1
2
4
6
输入样例 #2
6 2
2 3 0 5 6 0
输出样例 #2
2
5
输入样例 #3
4 1
0 0 0 0
输出样例 #3
1
2
3
4
输入样例 #4
6 2
0 0 1 0 4 5
输出样例 #4
1
3
4
6