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

.

Input

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

.

Output

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.

Examples

Input
3
2 3 2
Output
2 2 3 
Input
3
1 2 3
Output
1 2 3 

Note

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.

题解:输入写成数组,然后循环,循环到谁num++,如果num==2输出

ac代码:

#include<iostream>
#include<cstring>
using namespace std;
int a[1100];
int main()
{
    int fl,n,x;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        int b[1100]={0};
        b[i]++;
        x=a[i];
        for(;;)
        {
            b[x]++;
            if(b[x]==2) break;
            x=a[x];
        }
        if(i==1) cout<<x;
        else cout<<' '<<x;
    }
    cout<<endl;
    return 0;
}

水题----B - Badge CodeForces - 1020B的更多相关文章

  1. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  2. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  3. Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题

    题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...

  4. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  6. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  7. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  8. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  9. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

随机推荐

  1. Spring Boot2+Resilience4j实现容错之Bulkhead

    Resilience4j是一个轻量级.易于使用的容错库,其灵感来自Netflix Hystrix,但专为Java 8和函数式编程设计.轻量级,因为库只使用Vavr,它没有任何其他外部库依赖项.相比之下 ...

  2. Android Studio 插件 ADBWifi 无线调试真机

    长话短说,步骤如下 Android Studio 安装插件 ADB Wifi.这一步可以选择AS->Settings->Plugins->Market搜索:或者可以选择去插件官网下载 ...

  3. 【秒懂Java】【第1章_初识Java】02_软件开发

    通过上一篇文章<01_编程语言>,我们了解到 Java是众多编程语言中的其中一种 编程语言可以用来开发软件 因此,我们即将要学习的Java技术,是属于软件开发的范畴.那软件开发的前景如何呢 ...

  4. pycharm中导入包失败的解决办法

    将鼠标移动到requests处,出现如下提示 按住alt+enter键,点击install package requests即可安装requests包 安装成功后

  5. 阿里云安全组规则授权对象设置为固定IP段访问

    阿里云的ESC建站需要在安全组放通一些端口才能正常访问,所以我们在开放端口的时候就直接设置了全部ip可访问,授权对象填入0.0.0.0/0,意味着允许全部ip访问或者禁止全部ip访问. 但是我们有了一 ...

  6. JavaScript图形实例:再谈IFS生成图形

    在“JavaScript图形实例:迭代函数系统生成图形”一文中,我们介绍了采用迭代函数系统(Iterated Function System,IFS)创建分形图案的一些实例.在该文中,仿射变换函数W的 ...

  7. day63 django入门(4)

    目录 一.CBV源码解析 二.模版语法 1 传值 2 过滤器(最多只能传两个参数) 3 标签 4 自定义过滤器,标签,inclusion_tag 4.1 自定义过滤器 4.2 自定义标签(可以传多个参 ...

  8. day30 继承、派生与多态,类中方法和内置函数

    目录 一.多继承出现的问题(mixins机制) 二.派生与方法重用 三.多态 1 什么是多态 2 为什么要有多态 3 python中多态的鸭子类型 四.绑定方法与非绑定方法 1 绑定方法 1.1对象的 ...

  9. 函数默认参数的TDZ

    我们知道块级作用域会有TDZ. 其实方法参数也存在TDZ function add(first = second, second) { return first + second; } console ...

  10. java 面向对象(八):面向对象的特征一:封装性

    面向对象的特征一:封装与隐藏1.为什么要引入封装性?我们程序设计追求“高内聚,低耦合”.高内聚 :类的内部数据操作细节自己完成,不允许外部干涉:低耦合 :仅对外暴露少量的方法用于使用. 隐藏对象内部的 ...