#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
int P[MAXN];
bool b[MAXN];
int main(int argc, char* argv[]) {
  int n, c, begin;
  scanf("%d", &n);
  c = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &P[i]);
    if (P[i] == i) c = i;
  }
  if (c != -1) {
    printf("YES\n");
    for (int i = 1; i <= n; i++)
      if (P[i] != c) printf("%d %d\n", c, P[i]);
  } else {
    vector<vector<int> > cycles;
    vector<int> cycle;
    int i2cycle = -1;
    for (int i = 1; i <= n; i++) {
      if (!b[i]) {
        cycle.clear();
        c = i;
        begin = i;
        b[c] = true;
        cycle.push_back(c);
        while (P[c] != begin) {
          c = P[c];
          cycle.push_back(c);
          b[c] = true;
        }
        if (cycle.size() == 2)
          i2cycle = cycles.size();
        else if (cycle.size() % 2 == 1) {
          i2cycle = -1;
          break;
        }
        cycles.push_back(cycle);
      }
    }
    if (i2cycle == -1) {
      printf("NO\n");
    } else {
      printf("YES\n");
      printf("%d %d\n", cycles[i2cycle][0], cycles[i2cycle][1]);
      for (int i = 0; i < cycles.size(); i++)
        if (i != i2cycle) {
          for (int j = 0; j < cycles[i].size(); j++) {
            if (j & 1)
              printf("%d %d\n", cycles[i2cycle][0], cycles[i][j]);
            else
              printf("%d %d\n", cycles[i2cycle][1], cycles[i][j]);
          }
        }
    }
  }
  return 0;
}
