#include <bits/stdc++.h>
using namespace std;
bool bo[1000500];
int a[1000500];
int main() {
  int n, p;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  int flag = 0, pos1, pos2;
  int ok = 0;
  for (int i = 1; i <= n; ++i) {
    if (bo[i]) continue;
    int p = a[i];
    bo[i] = true;
    int c = 1;
    while (!bo[p]) {
      bo[p] = true;
      p = a[p];
      c++;
    }
    if (c > 2 && (c & 1)) ok = 1;
    if (c == 1) {
      flag = 1;
      pos1 = i;
    }
  }
  if (flag == 1) {
    puts("YES");
    for (int i = 1; i <= n; ++i)
      if (i != pos1) printf("%d %d\n", pos1, i);
    return 0;
  }
  if (ok == 1) {
    puts("NO");
    return 0;
  }
  memset(bo, 0, sizeof(bo));
  for (int i = 1; i <= n; ++i) {
    int p = a[i];
    bo[i] = true;
    int c = 1;
    while (!bo[p]) {
      bo[p] = true;
      p = a[p];
      c++;
    }
    if (c == 2) {
      flag = 1;
      pos1 = i;
      pos2 = a[i];
    }
  }
  if (flag == 1) {
    puts("YES");
    printf("%d %d\n", pos1, pos2);
    memset(bo, 0, sizeof(bo));
    for (int i = 1; i <= n; ++i) {
      if (i == pos1 || i == pos2) continue;
      if (bo[i] == true) continue;
      int p = a[i];
      bo[i] = true;
      printf("%d %d\n", pos1, i);
      int ff = 1;
      while (!bo[p]) {
        bo[p] = true;
        if (ff)
          printf("%d %d\n", pos2, p);
        else
          printf("%d %d\n", pos1, p);
        p = a[p];
        ff = 1 - ff;
      }
    }
    return 0;
  }
  puts("NO");
}
