#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, cnt, root, x;
int a[maxn];
bool v[maxn];
vector<int> q[maxn];
inline void read(int &k) {
  int f = 1;
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
int main() {
  read(n);
  int exroot = 0;
  for (int i = 1; i <= n; i++) read(a[i]), exroot = (a[i] == i) ? i : exroot;
  if (exroot) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (i != exroot) printf("%d %d\n", exroot, i);
    return 0;
  }
  bool flag = 0;
  for (int i = 1; i <= n; i++)
    if (!v[i]) {
      int x = a[i];
      q[++cnt].push_back(i);
      v[i] = 1;
      while (!v[x]) q[cnt].push_back(x), v[x] = 1, x = a[x];
      if (q[cnt].size() & 1) return puts("NO"), 0;
      if (q[cnt].size() == 2) flag = 1, root = cnt;
    }
  if (!flag) return puts("NO"), 0;
  puts("YES");
  printf("%d %d\n", q[root][0], q[root][1]);
  for (int i = 1; i <= cnt; i++)
    if (i != root) {
      int x = q[root][0], y = q[i][1];
      for (int j = 1; j <= q[i].size(); j++)
        printf("%d %d\n", x, y), x = a[x], y = a[y];
    }
}
