CF1020B.Badge
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 pa.
After that, the teacher came to student pa and made a hole in his badge as well. The student in reply said that the main culprit was student ppa.
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 pi. 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.
在暑期信息学学校中,如果学生表现不好,老师就会在他的校徽上打一个洞。今天,一位老师抓到了一群 n 名学生又在搞恶作剧。
假设这些学生编号为 1 到 n。老师首先来到学生 a 处,并在他的校徽上打了一个洞。然而,该学生辩称,真正的主谋是另一位学生 pa。
接着,老师又去找学生 pa,同样在他的校徽上打了一个洞。该学生则回应说,真正的主谋是学生 ppa。
这一过程持续了一段时间。但由于学生总数有限,老师最终来到了一名校徽上已经有一个洞的学生处。
此时,老师在该学生的校徽上打了第二个洞,并认为整个过程就此结束,随后便去洗桑拿了。
你并不知道老师最初抓住的是哪一名学生。但你知道所有的 pi 值。你的任务是:对每个学生 a,求出——若最初被抓的学生是 a,那么最终校徽上有两个洞的学生是谁?
输入格式
The first line of the input contains the only integer n (1≤n≤1000) — the number of the naughty students.
The second line contains n integers p1, ..., pn (1≤pi≤n), where pi indicates the student who was reported to the teacher by student i.
输入的第一行包含一个整数 n(1≤n≤1000)—— 表示淘气学生的数量。
第二行包含 n 个整数 p1, ..., pn(1≤pi≤n),其中 pi 表示学生 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 到 n 的每位学生 a,输出若学生 a 是第一个被老师抓到的学生,则哪位学生将在徽章上获得两个洞。
输入输出样例
输入#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.

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.
该图片对应第一个样例测试用例。

当 a=1 时,教师依次访问学生 1、2、3、2,学生 2 是其徽章上被打出第二个孔的人。
当 a=2 时,教师依次访问学生 2、3、2,学生 2 的徽章上被打出第二个孔。当 a=3 时,教师依次访问学生 3、2、3,学生 3 的徽章上被打出第二个孔。
对于第二个样例测试用例,显然无论教师从哪位学生开始,该学生都将是在其徽章上被打出第二个孔的人。
输入解题思路,AI测评打分。不知道怎么写?