Submission #1010539

#TimeUsernameProblemLanguageResultExecution timeMemory
1010539ivopavCrazy old lady (IZhO13_crazy)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; bool dob(vector<int> lis,vector<int> lis2,int ind,int n){ vector<bool> bio(n,0); bio[ind]=1; for (int i=0;i<n;i++){ if (i==lis[ind]){ continue; } if (bio[i]==0 && lis[i]!=i){ return 0; } bio[lis2[i]]=1; } return 1; } void prim(){ int n; cin >> n; vector<int> lis={}; vector<int> lis2(n,0); for (int i=0;i<n;i++){ int unos; cin >> unos; lis.push_back(--unos); lis2[unos]=i; } vector<int> rje={}; for (int i=0;i<n;i++){ if (dob(lis,lis2,i,n)){ rje.push_back(i); } } if (rje.size()==1){ cout << rje[0]+1 << "\n"; } else { cout << "0\n"; } } int main(){ long long int t; cin >> t; for (long long int i=0;i<t;i++){ prim(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...