#include <bits/stdc++.h>
const int maxn = 110000;
int p[maxn + 1], clen[maxn + 1];
bool done[maxn + 1];
int n;
int g1, g2, g3, g4;
void init() {
  int i, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &p[i]);
}
void calc_clen() {
  int i, len, j;
  for (i = 1; i <= n; ++i) done[i] = false;
  for (i = 1; i <= n; ++i)
    if (!done[i]) {
      if (p[i] == i) {
        clen[i] = 1;
        done[i] = true;
        continue;
      }
      j = i;
      len = 0;
      do {
        done[j] = true;
        ++len;
        j = p[j];
      } while (j != i);
      j = i;
      do {
        clen[j] = len;
        j = p[j];
      } while (j != i);
    }
}
void work() {
  if (n == 1) {
    printf("YES\n");
    exit(0);
  }
  if (n == 2) {
    printf("YES\n1 2\n");
    exit(0);
  }
  calc_clen();
  int i;
  g1 = g2 = g3 = 0;
  for (i = 1; i <= n; ++i)
    if (clen[i] == 1)
      ++g1;
    else if (clen[i] == 2)
      ++g2;
    else if (clen[i] % 2 == 1)
      ++g3;
    else
      ++g4;
  if (g1 == 0) {
    if ((!g2) || (g3)) {
      printf("NO\n");
      exit(0);
    }
  }
}
void output() {
  int i, j, k;
  int prev = -1;
  printf("YES\n");
  if (g1) {
    for (i = 1; i <= n; ++i)
      if (clen[i] == 1) {
        if (prev != -1) printf("%d %d\n", prev, i);
        prev = i;
      }
    for (i = 1; i <= n; ++i)
      if (clen[i] > 1) printf("%d %d\n", prev, i);
  } else {
    for (i = 1; i <= n; ++i) done[i] = false;
    for (i = 1; i <= n; ++i)
      if (p[p[i]] == i) break;
    printf("%d %d\n", i, p[i]);
    done[i] = done[p[i]] = true;
    for (j = 1; j <= n; ++j)
      if (!done[j]) {
        k = j;
        while (true) {
          printf("%d %d\n", i, k);
          printf("%d %d\n", p[i], p[k]);
          done[k] = done[p[k]] = true;
          k = p[p[k]];
          if (k == j) break;
        }
      }
  }
}
int main() {
  init();
  work();
  output();
  return 0;
}
