305388: CF1020B. Badge

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Badge

题意翻译

### 题目描述 在一所学校,如果一个学生表现不好,老师就会在他的徽章上打一个洞。今天,老师逮到了n名学生在搞恶作剧。 这些学生从1到n编号。老师先逮到了a学生然后在他的徽章上打了个洞。但是这个学生说带头的是另一个学生pa。 于是老师又抓住学生pa在他的徽章上也打了个洞。这个学生又说其实是学生ppa在带头搞恶作剧。 这个过程一直持续了好一会儿,不过因为这些学生是有限的,最后老师抓住了一个徽章上已经有一个洞的学生。 在给这个倒霉孩子的徽章上又打了个洞以后,老师觉得有点累,需要蒸个桑拿于是他就不再继续了。 你不知道谁是老师逮到的第一个学生,但是你知道所有的数字pi。对于每一个a,如果第一个被逮到的学生是a,你的任务是找到谁会是徽章上面有两个洞的学生。 ### 输入格式 第一行只有一个数字 n (1 <= n <=1000) ,表示搞恶作剧的学生的人数。 第二行有n个数字,p1, ..., pn (1<= pi <= n), pi表示被学生i指认是带头搞恶作剧的学生的编号。 ### 输出格式 对从1 到 n之间的每个学生 a,如果a是第一个被抓到的学生,输出谁会是徽章上面有两个洞的学生。 ### 样例说明 本图说明第一个样例. ![图片](http://codeforces.com/predownloaded/e6/2f/e62f6279b291a91d10dcf8b13b483a9dc5659758.png) 当a = 1, 老师的打洞顺序是1->2->3->2,输出2(2的徽章上会有俩洞); 当a = 2, 老师的打洞顺序是 2->3->2,输出2; 当a = 3,老师的打洞顺序是3->2->3,输出3。 对于第二个样例,不管老师先逮到谁,这个第一个被老师逮到的倒霉孩子将会得到两个洞。

题目描述

In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $ n $ students doing yet another trick. Let's assume that all these students are numbered from $ 1 $ to $ n $ . The teacher came to student $ a $ and put a hole in his badge. The student, however, claimed that the main culprit is some other student $ p_a $ . After that, the teacher came to student $ p_a $ and made a hole in his badge as well. The student in reply said that the main culprit was student $ p_{p_a} $ . This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge. After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna. You don't know the first student who was caught by the teacher. However, you know all the numbers $ p_i $ . Your task is to find out for every student $ a $ , who would be the student with two holes in the badge if the first caught student was $ a $ .

输入输出格式

输入格式


The first line of the input contains the only integer $ n $ ( $ 1 \le n \le 1000 $ ) — the number of the naughty students. The second line contains $ n $ integers $ p_1 $ , ..., $ p_n $ ( $ 1 \le p_i \le n $ ), where $ p_i $ indicates the student who was reported to the teacher by student $ i $ .

输出格式


For every student $ a $ from $ 1 $ to $ n $ print which student would receive two holes in the badge, if $ a $ was the first student caught by the teacher.

输入输出样例

输入样例 #1

3
2 3 2

输出样例 #1

2 2 3 

输入样例 #2

3
1 2 3

输出样例 #2

1 2 3 

说明

The picture corresponds to the first example test case. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1020B/21af1be4efeda0d910beae794a0c6c7034474400.png)When $ a = 1 $ , the teacher comes to students $ 1 $ , $ 2 $ , $ 3 $ , $ 2 $ , in this order, and the student $ 2 $ is the one who receives a second hole in his badge. When $ a = 2 $ , the teacher comes to students $ 2 $ , $ 3 $ , $ 2 $ , and the student $ 2 $ gets a second hole in his badge. When $ a = 3 $ , the teacher will visit students $ 3 $ , $ 2 $ , $ 3 $ with student $ 3 $ getting a second hole in his badge. For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.

Input

题意翻译

### 题目描述 在一所学校,如果一个学生表现不好,老师就会在他的徽章上打一个洞。今天,老师逮到了n名学生在搞恶作剧。 这些学生从1到n编号。老师先逮到了a学生然后在他的徽章上打了个洞。但是这个学生说带头的是另一个学生pa。 于是老师又抓住学生pa在他的徽章上也打了个洞。这个学生又说其实是学生ppa在带头搞恶作剧。 这个过程一直持续了好一会儿,不过因为这些学生是有限的,最后老师抓住了一个徽章上已经有一个洞的学生。 在给这个倒霉孩子的徽章上又打了个洞以后,老师觉得有点累,需要蒸个桑拿于是他就不再继续了。 你不知道谁是老师逮到的第一个学生,但是你知道所有的数字pi。对于每一个a,如果第一个被逮到的学生是a,你的任务是找到谁会是徽章上面有两个洞的学生。 ### 输入格式 第一行只有一个数字 n (1 <= n <=1000) ,表示搞恶作剧的学生的人数。 第二行有n个数字,p1, ..., pn (1<= pi <= n), pi表示被学生i指认是带头搞恶作剧的学生的编号。 ### 输出格式 对从1 到 n之间的每个学生 a,如果a是第一个被抓到的学生,输出谁会是徽章上面有两个洞的学生。 ### 样例说明 本图说明第一个样例. ![图片](http://codeforces.com/predownloaded/e6/2f/e62f6279b291a91d10dcf8b13b483a9dc5659758.png) 当a = 1, 老师的打洞顺序是1->2->3->2,输出2(2的徽章上会有俩洞); 当a = 2, 老师的打洞顺序是 2->3->2,输出2; 当a = 3,老师的打洞顺序是3->2->3,输出3。 对于第二个样例,不管老师先逮到谁,这个第一个被老师逮到的倒霉孩子将会得到两个洞。

加入题单

上一题 下一题 算法标签: