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. C#数据结构与算法系列(十四):递归——八皇后问题(回溯算法)

    1.介绍 八皇后问题,是一个古老而著名的问题,是回溯算法的经典案例,该问题是国际西洋棋棋手马克斯.贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即 任意两个皇后都不能处 ...

  2. html里输入框和密码框的提示文字怎么弄

    HTML5 新增属性,浏览器版本低于IE8应该不支持 placeholder 属性 placeholder 属性规定用以描述输入字段预期值的提示(样本值或有关格式的简短描述). 该提示会在用户输入值之 ...

  3. Docker文件系统实战

    关键词:Docker 联合文件系统 镜像 容器 云信私有化 在本文中,我们来实战构建一个Docker镜像,然后实例化容器,在Docker的生命周期中详细分析一下Docker的文件存储情况和Docker ...

  4. Spring Cloud系列教程第九篇-Eureka自我保护机制

    Spring Cloud系列教程第九篇-Eureka自我保护机制 本文主要内容: 1:自我保护介绍 2:导致原因分析 3:怎么禁止自我保护 本文是由凯哥(凯哥Java:kagejava)发布的< ...

  5. 猿灯塔:疫情冲击,去体验远程面试被怼10分钟,今年Java开发找工作真难

    网行业,美团王兴曾说:“2019年可能会是过去十年里最差的一年,却是未来十年里最好的一年”.没想到预言竟然快成真了? 年前很多企业一波裁员,2020年又受疫情影响,延长了假期,各大企业复工时间拉长,招 ...

  6. GAN网络从入门教程(一)之GAN网络介绍

    GAN网络从入门教程(一)之GAN网络介绍 稍微的开一个新坑,同样也是入门教程(因此教程的内容不会是从入门到精通,而是从入门到入土).主要是为了完成数据挖掘的课程设计,然后就把挖掘榔头挖到了GAN网络 ...

  7. 每日一题 - 剑指 Offer 33. 二叉搜索树的后序遍历序列

    题目信息 时间: 2019-06-26 题目链接:Leetcode tag:分治算法 递归 难易程度:中等 题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果.如果是则返回 tr ...

  8. RISC-V发展现状

    欲观原文,请君移步 面对xilinx和ARM联合打造的生态链,FPGA底层RTL逻辑开发人员变得可有可无,有的公司软件工程师都可以直接上手,这让传统的FPGA人员面临着一个尴尬的境地,而RISC-V的 ...

  9. 富文本编辑器实现从word中复制图片(外挂)

    1问题 基于web的富文本编辑器的功能普遍较弱,而word是公认的宇宙第一好用的文档编辑器,所以许多人都习惯先在word中编辑,然后再将内容粘到web富文本编辑器中. 但是,这种操作有一个问题:图片带 ...

  10. 洛谷 P6082 [JSOI2015]salesman

    题意 给定一棵\(n\)个点的树,有点权,你从\(1\)号点开始一次旅行,最后回到\(1\)号点.每到达一个点,你就能获得等于该点点权的收益, 但每个点都有进入该点的次数限制,且每个点的收益只能获得一 ...