#include <bits/stdc++.h>
using namespace std;
int p[100005], vis[100005];
vector<int> v[100005];
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) v[i].clear();
    ans.clear();
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) cin >> p[i];
    int f = 1, mn = n;
    int rt;
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      int num = 0, x = i;
      while (!vis[x]) {
        num++;
        vis[x] = 1;
        x = p[x];
      }
      if (num == 1 || (num == 2 && mn > 1)) rt = x;
      mn = min(mn, num);
      v[num].push_back(x);
    }
    if (mn > 2) {
      cout << "NO" << endl;
      continue;
    }
    for (int i = mn; i <= n; i++) {
      if (v[i].size() == 0) continue;
      if (i % mn) {
        f = 0;
        break;
      }
      for (auto u : v[i]) {
        if (u == rt || p[u] == rt) continue;
        int uu = u;
        do {
          ans.push_back(make_pair(rt, uu));
          uu = p[uu];
          if (uu != u)
            ans.push_back(make_pair(p[rt], uu));
          else
            break;
          uu = p[uu];
        } while (uu != u);
      }
    }
    if (mn == 2) ans.push_back(make_pair(rt, p[rt]));
    if (!f)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (auto u : ans) cout << u.first << " " << u.second << endl;
    }
  }
  return 0;
}
