func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 1e6;   int n;   int p[N];   int division[2][N];   int dln[2];   bool u[N];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;     }     int index1 = -1, index2 = -1;     for (int i = 0; i < n; i++) {       if (p[i] == i) index1 = i;       if (p[p[i]] == i) index2 = i;     }     if (index1 != -1) {       puts( YES );       for (int i = 0; i < n; i++)         if (index1 != i) printf( %d %d n , index1 + 1, i + 1);       return 0;     }     if (index2 != -1) {       bool flag = true;       dln[0] = dln[1] = 0;       fill_n(u, n, 0);       u[index2] = u[p[index2]] = 1;       for (int i = 0; i < n; i++)         if (!u[i]) {           u[i] = 1;           division[0][dln[0]++] = i;           int curI = p[i], step = 1;           while (curI != i) {             u[curI] = 1;             division[step][dln[step]++] = curI;             step ^= 1;             curI = p[curI];           }           if (step == 1) {             flag = false;             break;           }         }       if (!flag) {         puts( NO );         return 0;       }       puts( YES );       printf( %d %d n , index2 + 1, p[index2] + 1);       for (int i = 0; i < dln[0]; i++)         printf( %d %d n , index2 + 1, division[0][i] + 1);       for (int i = 0; i < dln[1]; i++)         printf( %d %d n , p[index2] + 1, division[1][i] + 1);       return 0;     }     puts( NO );     return 0;   }   