#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int A[N], tot;
bool mark[N];
vector<int> ps[N];
bool cmp(const vector<int>& lhs, const vector<int>& rhs) {
  return lhs.size() < rhs.size();
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", A + i);
    A[i]--;
  }
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      int j = A[i];
      ps[tot].push_back(A[i] + 1);
      while (j != i) {
        ps[tot].push_back(A[j] + 1);
        mark[j] = true;
        j = A[j];
      }
      tot++;
    }
  sort(ps, ps + tot, cmp);
  bool odd = false;
  for (int i = 0; i < tot; i++) {
    if (int(ps[i].size()) > 1 && int(ps[i].size()) & 1) {
      odd = true;
    }
  }
  if (ps[0].size() > 2 || odd && ps[0].size() != 1) {
    puts("NO");
  } else {
    puts("YES");
    if (ps[0].size() == 2) {
      printf("%d %d\n", ps[0][1], ps[0][0]);
    }
    for (int i = 1, f = 0; i < tot; i++) {
      for (int v : ps[i]) {
        printf("%d %d\n", v, ps[0][f]);
        if (ps[0].size() > 1) f ^= 1;
      }
    }
  }
  return 0;
}
