#include <bits/stdc++.h>
using namespace std;
int n;
int p[211111], was[211111];
void gop(int t) {
  puts("YES");
  was[t] = 1;
  for (int i = 0; i < n; i++)
    if (!was[i]) {
      int x = i;
      int sz = 0;
      for (;;) {
        printf("%d %d\n", t + 1, x + 1);
        was[x] = 1;
        sz++;
        x = p[x];
        if (x == i) break;
      }
    }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  int t = -1;
  for (int i = 0; i < n; i++)
    if (p[i] == i) {
      t = i;
      break;
    }
  if (t != -1) {
    gop(t);
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (p[p[i]] == i) {
      t = i;
      break;
    }
  if (t == -1) {
    puts("NO");
    return 0;
  }
  was[t] = 1;
  was[p[t]] = 1;
  for (int i = 0; i < n; i++)
    if (!was[i]) {
      int x = i;
      int sz = 0;
      for (;;) {
        was[x] = 1;
        sz++;
        x = p[x];
        if (x == i) break;
      }
      if (sz % 2) {
        puts("NO");
        return 0;
      }
    }
  puts("YES");
  printf("%d %d\n", t + 1, p[t] + 1);
  for (int i = 0; i < n; i++) was[i] = 0;
  was[t] = 1;
  was[p[t]] = 1;
  for (int i = 0; i < n; i++)
    if (!was[i]) {
      int x = i;
      int sz = 0;
      for (;;) {
        if (sz % 2 == 0) {
          printf("%d %d\n", t + 1, x + 1);
        } else {
          printf("%d %d\n", p[t] + 1, x + 1);
        }
        was[x] = 1;
        sz++;
        x = p[x];
        if (x == i) break;
      }
    }
  return 0;
}
