#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  vector<int> p(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &p[i]);
    --p[i];
  }
  vector<pair<int, vector<int> > > cycles;
  for (int i = 0; i < N; ++i) {
    int j = i;
    vector<int> cycle;
    while (p[j] != -1) {
      cycle.push_back(j);
      int t = p[j];
      p[j] = -1;
      j = t;
    }
    if (cycle.size()) cycles.push_back(make_pair((int)cycle.size(), cycle));
  }
  sort(cycles.begin(), cycles.end());
  if (cycles[0].first == 1) {
    printf("YES\n");
    for (int i = 1; i < (int)cycles.size(); ++i)
      for (int j = 0; j < (int)cycles[i].second.size(); ++j)
        printf("%d %d\n", cycles[0].second[0] + 1, cycles[i].second[j] + 1);
    return 0;
  } else if (cycles[0].first == 2) {
    for (int i = 1; i < (int)cycles.size(); ++i)
      if (cycles[i].first % 2) {
        printf("NO\n");
        return 0;
      }
    printf("YES\n");
    printf("%d %d\n", cycles[0].second[0] + 1, cycles[0].second[1] + 1);
    int cnt = 0;
    for (int i = 1; i < (int)cycles.size(); ++i)
      for (int j = 0; j < (int)cycles[i].second.size(); ++j)
        printf("%d %d\n", cycles[0].second[cnt++ % 2] + 1,
               cycles[i].second[j] + 1);
    return 0;
  } else
    printf("NO\n");
}
