#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] == i) {
      cout << "YES" << endl;
      for (int t = 1; t <= n; t++) {
        if (i != t) cout << t << " " << i << endl;
      }
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[p[i]] == i) {
      {
        vector<bool> fl(n + 1, true);
        fl[i] = false;
        fl[p[i]] = false;
        for (int j = 1; j <= n; j++) {
          if (fl[j]) {
            int curr = 0;
            while (fl[j]) {
              fl[j] = false;
              curr++;
              j = p[j];
            }
            if (curr % 2 == 1) {
              cout << "NO" << endl;
              return 0;
            }
          }
        }
      }
      vector<bool> fl(n + 1, true);
      fl[i] = false;
      fl[p[i]] = false;
      int t = i;
      cout << "YES" << endl;
      cout << i << " " << p[i] << endl;
      for (int j = 1; j <= n; j++) {
        if (fl[j]) {
          while (fl[j]) {
            fl[j] = false;
            cout << j << " " << t << endl;
            t = p[t];
            j = p[j];
          }
        }
      }
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
