#include <bits/stdc++.h>
using namespace std;
const int maxn = 100111;
int n, fa[maxn], p[maxn];
int get(int x) {
  if (fa[x] == x) return x;
  return fa[x] = get(fa[x]);
}
int to[maxn];
vector<int> v[maxn];
vector<pair<int, int> > ans;
int main() {
  cin >> n;
  for (int i = 0; i <= n + 1; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    int fi = get(i), fp = get(p[i]);
    if (fi != fp) fa[fi] = fp;
  }
  for (int i = 1; i <= n; i++) {
    v[get(i)].push_back(i);
  }
  int minsize = 99999999, pb = 0;
  for (int i = 1; i <= n; i++) {
    if (!v[i].empty()) {
      int nowsize = v[i].size();
      if (minsize >= nowsize) {
        minsize = nowsize;
        pb = i;
      }
    }
  }
  if (minsize >= 3) {
    puts("NO");
    return 0;
  }
  bool is = 0;
  if (minsize == 2) ans.push_back(make_pair(v[pb][0], v[pb][1]));
  for (int i = 1; i <= n; i++) {
    if (v[i].empty() || i == pb) continue;
    int s = v[i].size();
    int j = v[i][0], k = v[pb][0], cnt = 0;
    while (cnt < s) {
      ans.push_back(make_pair(j, k));
      to[j] = k;
      j = p[j];
      cnt++;
      k = p[k];
    }
    if (to[p[j]] != p[k]) is = 1;
  }
  if (is) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
