Help me in optimizin this code

closed account (jLCX216C)
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;

while(t--){
int flag=0;
int n;
cin>>n;
int a[100000];
for(int i=1;i<=n;i++){
cin>>a[i]; // entering the elements into the array.
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(a[i]!=a[j] && a[a[i]] == a[a[j]]){
flag=1;
break;
}
}
}
if(flag!=1){
cout<<"No "<<endl;
}
else{
cout<<"Yes "<<endl;
}
flag=0;
}
return 0;
}
Topic archived. No new replies allowed.