Codeforces Round #503 (by SIS, Div. 2) B. Badge

Bryce1010模板
https://codeforces.com/contest/1020/problem/B

思路:
按题意模拟。应该没有坑吧

#include
using namespace std;
#define ll long long

const int MAXN=1011;

int m[MAXN];
int main()
{
    int n,x;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>m[i];
    }
    int cnt[MAXN];

    for(int i=1;i<=n;i++)
    {
        memset(cnt,0,sizeof(cnt));
        int j;
        cnt[i]++;
        for(j=m[i];;j=m[j])
        {
            cnt[j]++;
            if(cnt[j]>=2)break;
        }
        cout<" ";
    }
    cout<return 0;
}

你可能感兴趣的:(Codeforces Round #503 (by SIS, Div. 2) B. Badge)