#include <bits/stdc++.h>
using namespace std;
static const int N = 100001;
int l[N];
int num[N], k = 1;
int p[N];
int g[N];
int done[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%i", &p[i]);
  for (int i = 1; i <= n; i++)
    if (!g[i]) {
      int x = i;
      l[k] = i;
      while (!g[x]) {
        g[x] = k;
        x = p[x];
        num[k]++;
      }
      k++;
    }
  for (int i = 1; i < k; i++)
    if (num[i] == 1) {
      printf("YES\n");
      for (int j = 1; j <= n; j++)
        if (j != l[i]) printf("%i %i\n", j, l[i]);
      return 0;
    }
  int sol = 0;
  for (int i = 1; i < k; i++) {
    if (num[i] == 2) sol = i;
    if (num[i] % 2) {
      printf("NO\n");
      return 0;
    }
  }
  if (sol) {
    printf("YES\n");
    printf("%i %i\n", l[sol], p[l[sol]]);
    for (int i = 1; i <= n; i++)
      if (!done[i] && g[i] != sol) {
        int x = i;
        int k = 0;
        while (!done[x]) {
          done[x] = 1;
          printf("%i %i\n", x, k * l[sol] + (!k) * p[l[sol]]);
          x = p[x];
          k ^= 1;
        }
      }
  } else
    printf("NO\n");
  return 0;
}
