Submission #1010539

# Submission time Handle Problem Language Result Execution time Memory
1010539 2024-06-29T07:56:14 Z ivopav Crazy old lady (IZhO13_crazy) C++17
0 / 100
1 ms 348 KB
#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
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -