#include <bits/stdc++.h>
using namespace std;
const char yes[] = "YES";
const char no[] = "NO";
int p[100100], n, cyc[100100];
bool vst[100100], type[100100];
void init(void) {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; i = i + 1) scanf("%d", &p[i]);
}
void specialCase(void) {
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    if (p[i] == i) {
      printf("%s\n", yes);
      for (int j = (1), _b = (n); j <= _b; j = j + 1)
        if (j != i) printf("%d %d\n", i, j);
      exit(0);
    }
}
int findCycle(int s) {
  int u = s;
  int res = 1;
  while (true) {
    vst[u] = true;
    u = p[u];
    if (u == s) break;
    res++;
  }
  return (res);
}
void fillCycle(int s, int v) {
  int u = s;
  bool mode = 0;
  while (true) {
    cyc[u] = v;
    type[u] = mode;
    mode ^= 1;
    u = p[u];
    if (u == s) break;
  }
}
void process(void) {
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    if (!vst[i]) fillCycle(i, findCycle(i));
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    if (cyc[i] % 2 == 1) {
      printf("%s\n", no);
      return;
    }
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    if (cyc[i] == 2) {
      int x = i;
      int y = p[i];
      printf("%s\n", yes);
      printf("%d %d\n", x, y);
      for (int j = (1), _b = (n); j <= _b; j = j + 1)
        if (j != x && j != y) printf("%d %d\n", type[j] ? x : y, j);
      exit(0);
    }
  printf("%s\n", no);
}
int main(void) {
  init();
  specialCase();
  process();
  return 0;
}
