#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, br;
int p[MAXN], niz[MAXN], num[MAXN], bio[MAXN];
inline void ne() {
  printf("NO\n");
  exit(0);
}
void dfs1(int x) {
  if (bio[x]) return;
  bio[x] = br;
  num[br]++;
  dfs1(niz[x]);
}
void dfs2(int x) {
  if (bio[x]) return;
  bio[x] = 1;
  if (bio[niz[x]]) return;
  printf("%d %d\n", x, niz[x]);
  dfs2(niz[x]);
}
void dfs3(int x, int y) {
  if (bio[x]) return;
  bio[x] = 1;
  printf("%d %d\n", x, y);
  dfs3(niz[x], niz[y]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) niz[p[i]] = p[p[i]];
  br = 1;
  for (int i = 1; i <= n; i++)
    if (!bio[i]) {
      dfs1(i);
      br++;
    }
  int poc = 0, val = MAXN, grupa = 0;
  for (int i = 1; i <= n; i++)
    if (num[bio[i]] < val) {
      val = num[bio[i]];
      poc = i;
      grupa = bio[i];
    }
  if (num[grupa] > 2) ne();
  for (int i = 1; i < br; i++)
    if (num[i] % num[grupa] != 0) ne();
  printf("YES\n");
  memset(bio, 0, sizeof(bio));
  dfs2(poc);
  for (int i = 1; i <= n; i++)
    if (!bio[i]) dfs3(i, poc);
  return 0;
}
