#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int a[100100];
int p[100100];
bool f[100100];
set<pair<int, int> > S;
int main() {
  int n;
  int i;
  int j;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    p[a[i]] = i;
  }
  for (i = 1; i <= n; ++i) {
    if (a[i] == i) {
      printf("YES\n");
      for (j = 1; j <= n; ++j)
        if (i != j) printf("%d %d\n", i, j);
      return 0;
    }
  }
  pair<int, int> middle = make_pair(0, 0);
  for (i = 1; i <= n; ++i) {
    if (a[i] == p[i]) {
      middle.first = a[i];
      middle.second = i;
      break;
    }
  }
  memset(f, false, sizeof(bool) * 100100);
  if (middle == make_pair(0, 0)) {
    printf("NO");
    return 0;
  }
  for (i = 1; i <= n; ++i) {
    int sc = 0;
    if (!f[a[i]]) {
      j = a[i];
      while (!f[j]) {
        f[j] = true;
        sc++;
        j = p[j];
      }
      if (sc % 2 == 1) {
        printf("NO");
        return 0;
      }
    }
  }
  memset(f, false, sizeof(bool) * 100100);
  int x, y;
  printf("YES\n");
  printf("%d %d\n", x = middle.first, y = middle.second);
  S.insert(make_pair(middle.first, middle.second));
  S.insert(make_pair(middle.second, middle.first));
  f[middle.first] = true;
  f[middle.second] = true;
  for (i = 1; i <= n; ++i) {
    int q, w;
    if (!f[i]) {
      q = x;
      w = a[i];
      while (!S.count(make_pair(q, w))) {
        printf("%d %d\n", q, w);
        S.insert(make_pair(q, w));
        S.insert(make_pair(w, q));
        f[p[w]] = true;
        q = p[q];
        w = p[w];
      }
    }
  }
  return 0;
}
