#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793;
int n, now, m;
int p[500100];
int l[500100], r[500100];
int f[500100];
bool v[500100];
void init() {
  scanf("%d", &n);
  memset(v, false, sizeof(v));
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  now = 0;
  m = 0;
  for (int i = 1; i <= n; i++)
    if (!v[i]) {
      v[i] = true;
      l[++m] = (++now);
      r[m] = now;
      f[now] = i;
      int j = i;
      while (p[j] != i) {
        ++r[m];
        f[++now] = p[j];
        j = p[j];
        v[j] = true;
      }
    }
}
void work() {
  int p0;
  for (int i = 1; i <= m; i++) {
    if (l[i] == r[i]) {
      printf("YES\n");
      p0 = f[l[i]];
      for (int j = 1; j <= n; j++)
        if (p0 != j) {
          printf("%d %d\n", p0, j);
        }
      return;
    }
  }
  for (int i = 1; i <= m; i++)
    if ((r[i] - l[i] + 1) % 2) {
      printf("NO\n");
      return;
    }
  for (int i = 1; i <= m; i++)
    if (r[i] - l[i] == 1) {
      printf("YES\n");
      printf("%d %d\n", f[l[i]], f[r[i]]);
      for (int j = 1; j <= m; j++)
        if (i != j) {
          for (int k = l[j]; k <= r[j]; k++) {
            p0 = f[k];
            if ((k - l[i]) % 2)
              printf("%d %d\n", f[l[i]], p0);
            else
              printf("%d %d\n", f[r[i]], p0);
          }
        }
      return;
    }
  printf("NO\n");
}
int main() {
  init();
  work();
  return 0;
}
