#include <bits/stdc++.h>
using namespace std;
vector<int> g[100001];
int vis[100001];
bool ans = true;
void dfs(int n, int cnt) {
  vis[n] = cnt;
  for (int i = 0; i < g[n].size(); i++) {
    if (vis[g[n][i]] == -1)
      dfs(g[n][i], cnt ^ 1);
    else if (vis[g[n][i]] != (cnt ^ 1)) {
      ans = false;
    }
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  int a[n + 1];
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int rt = -1;
  for (int i = 1; i <= n; i++) {
    g[i].push_back(a[i]);
    g[a[i]].push_back(i);
    if (i == a[i]) {
      rt = i;
      break;
    }
  }
  if (rt != -1) {
    printf("YES\n");
    for (int i = 1; i <= n; i++) {
      if (i == rt) continue;
      printf("%d %d\n", i, rt);
    }
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i == a[a[i]]) {
      rt = i;
      break;
    }
  }
  if (rt == -1) {
    printf("NO\n");
    return 0;
  }
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (vis[i] == -1) {
      ans = true;
      dfs(i, 0);
    }
    if (ans == false) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  for (int i = 1; i <= n; i++) {
    if (i == rt || i == a[rt]) continue;
    if (vis[i])
      printf("%d %d\n", i, a[rt]);
    else
      printf("%d %d\n", i, rt);
  }
  printf("%d %d\n", rt, a[rt]);
  return 0;
}
