题解 | 谍中谍中谍中谍中谍...
谍中谍中谍中谍中谍...
https://www.nowcoder.com/practice/ee1246384c9b4066b67043ebb37fd9c9
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int n,p[N];
void solve(){
for(int i=1;i<=n;i++){
vector<bool> vis(n+1,false);
vis[i]=true;
int tp=i;
while(true){
tp=p[tp];
if(vis[tp]==true){
cout<<tp<<" ";
break;
}
vis[tp]=true;
}
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>p[i];
}
solve();
return 0;
}
