# Untitled

user_5668965
c_cpp
22 days ago
1.4 kB
0
Indexable
Never
```#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long
#define pb push_back
#define vll vector<ll>
#define vp vector<pair<ll, ll>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))
#define PrintAns(ans) cout << ans << endl
#define PrintAns2(a1, a2) cout << a1 << " " << a2 << endl
#define PrintAll(arr) fori(arr.size()) cout << arr[i] << " \n"[i == arr.size() - 1]
#define flagYN(flag) cout << ((flag) ? "YES" : "NO") << endl
#define fori(n) for (int i = 0; i < n; ++i)
#define forj(n) for (int j = 0; j < n; ++j)
#define fork(n) for (int k = 0; k < n; ++k)
#define K_VAL ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const int N = 1002;
vector<ll> ar[N + 1], vis(N + 1);

void call(ll n)
{
vis[n]++;
for (ll child : ar[n])
{
if (vis[child])
{cout << child << " ";
return;
}
call(child);
}
}

void solve(const int &tt)
{
// cout <<"case : "<< tt << endl;
ll n, x;
cin >> n;
fori(n) cin >> x, ar[i + 1].pb(x);
fori(n)
{
vis.assign(N + 1, 0);
call(i + 1);
}
}

int main()
{
K_VAL
int t = 1;
// cin >> t;
fori(t)
solve(i);
// PrintAns(solve(i));
// flagYN(solve(i));
return 0;
}```