#include <bits/stdc++.h>
using namespace std;
int n, a[1000000];
bool b[1000000];
int main() {
  cin >> n;
  {
    for (int i = 1; i <= n; ++i) b[i] = true;
  };
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] == i) {
      cout << "YES" << endl;
      b[i] = false;
      for (int j = 1; j <= n; j++) {
        if (b[j] == true) {
          int t = j;
          while (b[t] == true) {
            cout << i << ' ' << t << endl;
            b[t] = false;
            t = a[t];
          }
        }
      }
      return 0;
    }
  bool y1 = false, y2 = true;
  int st = 0;
  {
    for (int i = 1; i <= n; ++i) b[i] = true;
  };
  for (int i = 1; i <= n; i++)
    if (a[a[i]] == i) {
      y1 = true;
      st = i;
      break;
    }
  for (int i = 1; i <= n; i++)
    if (b[i] == true) {
      int k = 0, t = i;
      while (b[t] == true) {
        b[t] = false;
        k++;
        t = a[t];
      }
      if (k % 2 == 1) {
        y2 = false;
        break;
      }
    }
  if (y1 != true || y2 == false) {
    cout << "NO";
    return 0;
  }
  {
    for (int i = 1; i <= n; ++i) b[i] = true;
  };
  cout << "YES" << endl;
  cout << st << " " << a[st] << endl;
  for (int i = 1; i <= n; i++) {
    if (b[i] == true && i != st && a[st] != i) {
      int l = i, r = st;
      while (b[l] == true) {
        cout << l << " " << r << endl;
        b[l] = false;
        l = a[l];
        r = a[r];
      }
    }
  }
}
