#include <bits/stdc++.h>
inline int read() {
  int s = 0;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  do {
    s = s * 10 + c - '0';
  } while ((c = getchar()) >= '0' && c <= '9');
  return s;
}
const int N = 100010;
int n, i, j, nx[N], st, st2, l, tmp, ev;
bool b[N];
int main() {
  n = read();
  for (i = 1; i <= n; i++) nx[i] = read();
  l = -1;
  ev = 1;
  for (i = 1; i <= n; i++) {
    for (j = i, tmp = 0; !b[j]; j = nx[j], tmp++) b[j] = 1;
    if (l != 1 && tmp == 1) st = i, l = 1;
    if (l == -1 && tmp == 2) st = i, st2 = nx[i], l = 2;
    if (tmp & 1) ev = 0;
  }
  if (l == -1 || (l == 2 && !ev))
    printf("NO\n");
  else {
    printf("YES\n");
    if (l == 1) {
      for (i = 1; i <= n; i++)
        if (i != st) printf("%d %d\n", st, i);
    } else {
      printf("%d %d\n", st, st2);
      memset(b, 0, sizeof b);
      tmp = 0;
      for (i = 1; i <= n; i++) {
        if (i == st || i == st2) continue;
        for (j = i; !b[j]; j = nx[j], tmp ^= 1)
          b[j] = 1, printf("%d %d\n", j, tmp ? st2 : st);
      }
    }
  }
  return 0;
}
