#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n;
int fa[maxn];
bool vis[maxn];
int cnt_loop = 0;
vector<int> loop[maxn];
void get(int x, int id) {
  vis[x] = 1;
  loop[id].push_back(x);
  if (vis[fa[x]]) return;
  get(fa[x], id);
}
bool num[maxn];
int rid[maxn];
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &fa[i]);
  }
  for (register int i = 1; i <= n; i++) {
    if (!vis[i]) get(i, ++cnt_loop);
  }
  bool fg2 = 0;
  for (register int i = 1; i <= cnt_loop; i++) {
    num[loop[i].size()] = 1;
    rid[loop[i].size()] = i;
    if (((int)loop[i].size()) & 1) {
      fg2 = 1;
    }
  }
  if (num[1]) {
    printf("YES\n");
    for (register int i = 1; i <= cnt_loop; i++) {
      if (rid[1] == i) continue;
      for (register int j = 0; j < (int)loop[i].size(); j++) {
        printf("%d %d\n", loop[rid[1]][0], loop[i][j]);
      }
    }
  } else if (num[2] && !fg2) {
    printf("YES\n");
    for (register int i = 1; i <= cnt_loop; i++) {
      if (rid[2] == i) {
        printf("%d %d\n", loop[i][0], loop[i][1]);
        continue;
      }
      for (register int j = 0; j < (int)loop[i].size(); j++) {
        printf("%d %d\n", loop[rid[2]][j & 1], loop[i][j]);
      }
    }
  } else {
    printf("NO\n");
  }
  return 0;
}
