#include <bits/stdc++.h>
using namespace std;
int a[100005];
int fl[100005];
int main() {
  int n;
  scanf("%d", &n);
  int i;
  int valid = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) valid = i;
  }
  if (valid) {
    printf("YES\n");
    for (i = 1; i <= n; i++)
      if (i != valid) printf("%d %d\n", i, valid);
    return 0;
  }
  int co = 0;
  valid = 1;
  int rr = 0;
  for (i = 1; i <= n; i++) {
    int cur = i;
    co = 0;
    while (fl[cur] == 0) {
      fl[cur] = 1;
      cur = a[cur];
      co++;
    }
    if (co == 2) rr = i;
    if (co % 2) {
      valid = 0;
      break;
    }
  }
  if (valid) {
    if (rr == 0) {
      printf("NO\n");
      return 0;
    }
    printf("YES\n");
    for (i = 1; i <= n; i++) fl[i] = 0;
    printf("%d %d\n", rr, a[rr]);
    int i;
    fl[rr] = fl[a[rr]] = 1;
    for (i = 2; i <= n; i++) {
      if (fl[i] == 0) {
        int fir, sec;
        fir = i;
        sec = a[i];
        while (fl[fir] == 0) {
          sec = a[fir];
          printf("%d %d\n", rr, fir);
          printf("%d %d\n", a[rr], sec);
          fl[fir] = fl[sec] = 1;
          fir = a[sec];
        }
      }
    }
  } else
    printf("NO\n");
}
