#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 500 * 500 + 10;
const int inf = 1e9;
const long long mod = 1e9 + 7;
int getint() {
  char c;
  while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
    ;
  int ret = c - '0', sgn = 0;
  if (c == '-') sgn = 1, ret = 0;
  while ((c = getchar()) && c >= '0' && c <= '9') ret = ret * 10 + c - '0';
  if (sgn) ret = -ret;
  return ret;
}
vector<int> g[maxn], h[maxn];
int cnt;
int vis[maxn];
void dfs(int u) {
  vis[u] = 1;
  h[cnt].push_back(u);
  int sz = g[u].size();
  for (int i = 0; i < sz; i++) {
    int v = g[u][i];
    if (vis[v]) continue;
    dfs(v);
  }
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int i;
    for (i = 1; i <= n; i++) g[i].clear(), h[i].clear();
    for (i = 1; i <= n; i++) {
      int x = getint();
      g[i].push_back(x), g[x].push_back(i);
    }
    memset(vis, 0, sizeof(vis));
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        cnt++;
        dfs(i);
      }
    }
    int flag = 0, ff = 1;
    int center1 = -1, center2 = -1;
    for (int i = 1; i <= cnt; i++) {
      int sz = h[i].size();
      if (sz == 1) center1 = i, flag = 1;
      if (sz == 2) center2 = i, flag = 1;
      if (sz >= 3 && sz & 1) {
        ff = 0;
      }
    }
    if (center1 == -1 && center2 == -1) {
      puts("NO");
      continue;
    } else if (center1 == -1 && !ff) {
      puts("NO");
      continue;
    }
    puts("YES");
    if (center1 != -1) {
      int u = h[center1][0];
      for (int i = 1; i <= cnt; i++)
        if (i != center1) {
          int sz = h[i].size();
          for (int j = 0; j < sz; j++) {
            printf("%d %d\n", u, h[i][j]);
          }
        }
    } else {
      int u = h[center2][0], v = h[center2][1];
      printf("%d %d\n", u, v);
      for (int i = 1; i <= cnt; i++)
        if (i != center2) {
          int sz = h[i].size();
          for (int j = 0; j < sz; j++) {
            if (j & 1) {
              printf("%d %d\n", u, h[i][j]);
            } else
              printf("%d %d\n", v, h[i][j]);
          }
        }
    }
  }
  return 0;
}
