CF1020B.Badge

普及/提高-

通过率:0%

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 nn students doing yet another trick.

Let's assume that all these students are numbered from 11 to nn . The teacher came to student aa and put a hole in his badge. The student, however, claimed that the main culprit is some other student pap_a .

After that, the teacher came to student pap_a and made a hole in his badge as well. The student in reply said that the main culprit was student ppap_{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 pip_i . Your task is to find out for every student aa , who would be the student with two holes in the badge if the first caught student was aa .

输入格式

The first line of the input contains the only integer nn ( 1n10001 \le n \le 1000 ) — the number of the naughty students.

The second line contains nn integers p1p_1 , ..., pnp_n ( 1pin1 \le p_i \le n ), where pip_i indicates the student who was reported to the teacher by student ii .

输出格式

For every student aa from 11 to nn print which student would receive two holes in the badge, if aa 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.

When a=1a = 1 , the teacher comes to students 11 , 22 , 33 , 22 , in this order, and the student 22 is the one who receives a second hole in his badge.

When a=2a = 2 , the teacher comes to students 22 , 33 , 22 , and the student 22 gets a second hole in his badge. When a=3a = 3 , the teacher will visit students 33 , 22 , 33 with student 33 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.

首页