#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 1e5 + 10;   int n, p[N], h[N];   vector<int> g[N];   vector<pair<int, int> > ans;   void build(int x, int y) {     int m1 = g[x].size();     if (x == y) {       for (auto i = 0; i < m1 - 1; i++)         ans.push_back(pair<int, int>(g[x][i], g[x][i + 1]));       return;     }     for (auto i = 0; i < g[y].size(); i++)       ans.push_back(pair<int, int>(g[x][i % m1], g[y][i]));   }   void solve() {     int m = 0;     for (auto i = 1; i <= n; i++)       if (!h[i]) {         m++;         int cur = i;         while (!h[cur]) {           h[cur] = 1;           g[m].push_back(cur);           cur = p[cur];         }       }     int root = 1;     for (auto i = 1; i <= m; i++)       if (g[i].size() < g[root].size()) root = i;     if (g[root].size() > 2) {       printf( NO );       return;     }     for (auto i = 1; i <= m; i++)       if (g[i].size() % g[root].size()) {         printf( NO );         return;       }     for (auto i = 1; i <= m; i++) build(root, i);     if (ans.size() != n - 1) {       printf( NO n );       return;     }     printf( YES n );     for (auto i : ans) printf( %d %d n , i.first, i.second);   }   int main() {     scanf( %d , &n);     for (auto i = 1; i <= n; i++) scanf( %d , p + i);     solve();   }   