#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int nmax = 1e5 + 5;
int arr[nmax];
int plen[nmax];
int n;
int l1, l2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
  }
  for (int i = 1; i <= n; ++i) {
    if (!plen[i]) {
      int len = 1;
      int pos = i;
      while (arr[pos] != i) {
        ++len;
        pos = arr[pos];
      }
      pos = i;
      while (arr[pos] != i) {
        plen[pos] = len;
        pos = arr[pos];
      }
      plen[pos] = len;
      if (len == 1) {
        l1 = i;
      }
      if (len == 2) {
        l2 = i;
      }
    }
  }
  if (l1) {
    printf("YES\n");
    for (int i = 1; i <= n; ++i) {
      if (i != l1) {
        printf("%d %d\n", i, l1);
      }
    }
  } else {
    bool pos = true;
    for (int i = 1; i <= n; ++i) {
      if (plen[i] % 2) {
        pos = false;
      }
    }
    if (!l2) pos = false;
    if (pos) {
      int a = l2, b = arr[l2];
      printf("YES\n");
      printf("%d %d\n", a, b);
      plen[a] = 0;
      plen[b] = 0;
      for (int i = 1; i <= n; ++i) {
        if (plen[i]) {
          int loc = i;
          while (arr[loc] != i) {
            printf("%d %d\n", a, loc);
            swap(a, b);
            loc = arr[loc];
            plen[loc] = 0;
          }
          printf("%d %d\n", a, loc);
          swap(a, b);
          plen[loc] = 0;
        }
      }
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
