#include <bits/stdc++.h>
using namespace std;
vector<int> cycles[100000];
vector<int> permutation;
bool done[100000];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    a--;
    permutation.push_back(a);
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (done[i]) {
      continue;
    }
    int t = i;
    while (!done[t]) {
      cycles[k].push_back(t);
      done[t] = true;
      t = permutation[t];
    }
    k++;
  }
  bool cycle1 = false, cycle2 = false;
  int pos = -1;
  for (int i = 0; i < k; i++) {
    if (cycles[i].size() == 1) {
      cycle1 = true;
      pos = cycles[i][0];
      break;
    }
  }
  if (cycle1 == false) {
    for (int i = 0; i < k; i++) {
      if (cycles[i].size() == 2) {
        cycle2 = true;
        pos = i;
        break;
      }
    }
  }
  if (pos == -1) {
    printf("NO\n");
    return 0;
  }
  if (cycle2 == true) {
    for (int i = 0; i < k; i++) {
      if (i == pos) {
        continue;
      }
      if (cycles[i].size() % 2 && cycles[i].size() > 1) {
        printf("NO\n");
        return 0;
      }
    }
  }
  printf("YES\n");
  if (cycle1) {
    for (int i = 0; i < n; i++) {
      if (i != pos) {
        printf("%d %d\n", i + 1, pos + 1);
      }
    }
  } else {
    printf("%d %d\n", cycles[pos][0] + 1, cycles[pos][1] + 1);
    for (int i = 0; i < k; i++) {
      if (i == pos) {
        continue;
      }
      for (int j = 0; j < cycles[i].size(); j++) {
        printf("%d %d\n", cycles[pos][j % 2] + 1, cycles[i][j] + 1);
      }
    }
  }
  return 0;
}
