#include <bits/stdc++.h>
using namespace std;
int N, p[100005];
bool mark[100005];
vector<pair<int, int> > ci, ans;
vector<int> comp[100005];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < (int)N; i++) scanf("%d", &p[i + 1]);
  int cur = 0;
  for (int i = 1; i < (int)N + 1; i++)
    if (!mark[i]) {
      int nd = i, sz = 0;
      while (!mark[nd]) {
        mark[nd] = true;
        comp[cur].push_back(nd);
        sz++;
        nd = p[nd];
      }
      ci.push_back(make_pair(sz, cur++));
    }
  sort(ci.begin(), ci.end());
  if (ci[0].first > 2) {
    puts("NO");
    return 0;
  }
  int c1 = ci[0].second, l = ci[0].first;
  for (int i = 1; i < (int)ci.size(); i++) {
    int c2 = ci[i].second;
    if (ci[i].first % l > 0) {
      puts("NO");
      return 0;
    }
    for (int j = 0; j < (int)comp[c2].size(); j++) {
      int x = comp[c1][(j % l)], y = comp[c2][j];
      ans.push_back(make_pair(x, y));
    }
  }
  puts("YES");
  if (ci[0].first == 2)
    printf("%d %d\n", comp[ci[0].second][0], comp[ci[0].second][1]);
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
