#include <bits/stdc++.h>
using namespace std;
int bx[2], p[100010], vis[100010];
bool in[100010];
vector<int> ans;
bool dfs(int pos, int step) {
  vis[pos] = step;
  ans.push_back(pos);
  if (!vis[p[pos]]) return dfs(p[pos], step + 1);
  int t = step + 1 - vis[p[pos]];
  return bx[0] == bx[1] || t == 1 || t % 2 == 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
    in[p[i]] = 1;
    if (i == p[i]) bx[0] = bx[1] = i;
  }
  if (bx[0] == 0)
    for (int i = 1; i <= n; i++)
      if (i == p[p[i]]) {
        bx[0] = i;
        bx[1] = p[i];
        break;
      }
  if (bx[0] == 0)
    puts("NO");
  else {
    vis[bx[0]] = vis[bx[1]] = 1;
    bool flag = 1;
    for (int i = 1; flag && i <= n; i++)
      if (!in[i]) flag = dfs(i, 1);
    if (!flag) {
      puts("NO");
      return 0;
    }
    for (int i = 1; flag && i <= n; i++)
      if (!vis[i]) flag = dfs(i, 1);
    if (!flag) {
      puts("NO");
      return 0;
    }
    puts("YES");
    if (bx[0] != bx[1]) printf("%d %d\n", bx[0], bx[1]);
    int len = ans.size();
    for (int i = 0; i < len; i++) printf("%d %d\n", bx[i & 1], ans[i]);
  }
}
