# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010539 | ivopav | Crazy old lady (IZhO13_crazy) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |