#include <bits/stdc++.h>
using namespace std;
int A[1 << 20];
pair<int, int> E[1 << 20];
int f(int n) {
  int i, j;
  for (i = (0); i < (n); ++i)
    if (A[i] == i) {
      for (j = (0); j < (n - 1); ++j)
        E[j] = pair<int, int>(i, j < i ? j : j + 1);
      return 1;
    }
  int a = -1;
  int b = -1;
  for (i = (0); i < (n); ++i)
    if (A[A[i]] == i) {
      a = i;
      b = A[a];
      break;
    }
  if (a == -1) return 0;
  A[a] = A[b] = -1;
  int cnt = 0;
  for (i = (0); i < (n); ++i)
    if (A[i] != -1) {
      vector<int> v;
      int t = i;
      while (A[t] != -1) {
        v.push_back(t);
        int n = A[t];
        A[t] = -1;
        t = n;
      }
      if (int((v).size()) % 2 != 0) return 0;
      for (j = (0); j < (int((v).size())); ++j) {
        E[cnt] = pair<int, int>(j % 2 == 0 ? a : b, v[j]);
        ++cnt;
      }
    }
  E[cnt] = pair<int, int>(a, b);
  ++cnt;
  if (cnt != n - 1) throw 0;
  return 1;
}
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = (0); i < (n); ++i) {
    scanf("%d", &A[i]);
    --A[i];
  }
  if (f(n) == 0)
    printf("NO\n");
  else {
    printf("YES\n");
    for (i = (0); i < (n - 1); ++i)
      printf("%d %d\n", E[i].first + 1, E[i].second + 1);
  }
  return 0;
};
