func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000005;   int N;   vector<int> G[MAX_N];   int cyid[MAX_N], Q[MAX_N];   vector<vector<int>> cycles, newcycles;   void find_cycle(int s, int curid) {     cyid[s] = curid;     cycles.back().push_back(s);     for (int i = 0; i < G[s].size(); i++) {       if (cyid[G[s][i]] == -1) {         find_cycle(G[s][i], curid);       }     }   }   void get_cycles() {     fill(cyid + 1, cyid + N + 1, -1);     int nCycles = 0;     for (int i = 1; i <= N; i++) {       if (cyid[i] == -1) {         cycles.push_back(vector<int>());         find_cycle(i, ++nCycles);       }     }   }   void construct_root_permutation() {     int numEven = 0, numOdd = 0;     for (vector<int> p : cycles) {       if (p.size() % 2 == 0)         numEven++;       else         numOdd++;     }     if (numEven % 2 == 1) {       printf( -1 n );       return;     }     sort(cycles.begin(), cycles.end(),          [](vector<int> a, vector<int> b) { return a.size() < b.size(); });     for (int i = 0; i < cycles.size();) {       if (cycles[i].size() % 2 == 1) {         if (cycles[i].size() == 1)           newcycles.push_back({cycles[i][0]});         else {           vector<int> newcyk;           int ptr1 = 0, ptr2 = (cycles[i].size() - 1) / 2 + 1;           for (int j = 0; j < cycles[i].size() / 2; j++) {             newcyk.push_back(cycles[i][ptr1++]);             newcyk.push_back(cycles[i][ptr2++]);           }           newcyk.push_back(cycles[i][ptr1]);           newcycles.emplace_back(newcyk);         }         i++;       } else {         if (i + 1 < cycles.size()) {           if (cycles[i].size() != cycles[i + 1].size()) {             printf( -1 n );             return;           } else {             vector<int> merged;             for (int j = 0; j < cycles[i].size(); j++) {               merged.push_back(cycles[i][j]);               merged.push_back(cycles[i + 1][j]);             }             newcycles.emplace_back(merged);             i += 2;           }         } else {           printf( -1 n );           return;         }       }     }     for (int i = 0; i < newcycles.size(); i++) {       if (newcycles[i].size() == 1)         Q[newcycles[i][0]] = newcycles[i][0];       else {         newcycles[i].push_back(newcycles[i][0]);         for (int j = 0; j < newcycles[i].size() - 1; j++) {           int next = newcycles[i][j + 1];           Q[newcycles[i][j]] = next;         }       }     }     for (int i = 1; i <= N; i++) printf( %d  , Q[i]);     printf(  n );   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int pi;       scanf( %d , &pi);       G[i].push_back(pi);     }     get_cycles();     construct_root_permutation();     return 0;   }   