Submission #1010727

#TimeUsernameProblemLanguageResultExecution timeMemory
1010727ivopavCrazy old lady (IZhO13_crazy)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; bool dob(vector<int> lis2,vector<int> lis,int ind,int n){ vector<bool> bio(n,0); bio[ind]=1; for (int i=0;i<n;i++){ if (i==lis2[ind]){ continue; } if (bio[i]==0 && lis2[i]!=i){ return 0; } bio[lis[i]]=1; } return 1; } void prim(){ int n; cin >> n; vector<int> lis2={}; vector<int> lis(n,0); for (int i=0;i<n;i++){ int unos; cin >> unos; lis2.push_back(--unos); lis[unos]=i; } vector<int> rje={}; for (int i=0;i<n;i++){ if (dob(lis2,lis,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...