#include <bits/stdc++.h>
using namespace std;
const int DEBUG = 0;
namespace defs {
int read() {
  int aa, bb = 1, ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  ch == '-' ? aa = 0, bb = -1 : aa = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - '0';
  return aa * bb;
}
const unsigned int rand_x = 1401010315;
const unsigned int rand_y = 1000000019;
unsigned int rand_cur;
unsigned int rand_int() { return rand_cur = rand_cur * rand_x + rand_y; }
const int inf = 1071026353;
const int mod = 1000000007;
const int modx = 998244353;
const int maxn = 100010;
}  // namespace defs
namespace lightningwork {
using namespace defs;
int n, p[maxn], vis[maxn];
int list[maxn], tot;
int dfs(int now, int pr = 0) {
  vis[now] = 1;
  if (pr) list[++tot] = now;
  if (vis[p[now]]) return 1;
  return dfs(p[now], pr) + 1;
}
void work() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    p[i] = read();
    if (p[i] == i) {
      puts("YES");
      for (int j = 1; j <= n; ++j) {
        if (j != i) printf("%d %d\n", i, j);
      }
      return;
    }
  }
  int x = -1, y = -1, odd = 0;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    int siz = dfs(i);
    if (siz == 2) x = i, y = p[i];
    if (siz > 2 && siz % 2) odd = 1;
  }
  if (x == -1 || odd) {
    puts("NO");
    return;
  }
  puts("YES");
  printf("%d %d\n", x, y);
  memset(vis, 0, sizeof vis);
  vis[x] = vis[y] = 1;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    tot = 0;
    dfs(i, 1);
    for (int j = 1; j <= tot; ++j) {
      printf("%d %d\n", list[j], j & 1 ? x : y);
    }
  }
}
}  // namespace lightningwork
int main() {
  if (0)
    freopen(
        "work"
        ".in",
        "r", stdin),
        freopen(
            "work"
            ".out",
            "w", stdout);
  lightningwork::work();
  if (0) fclose(stdin), fclose(stdout);
  return 0;
}
