#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, a[N], num[N];
bool flag[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] == i) {
      puts("YES");
      for (int j = 1; j <= n; j++)
        if (i != j) printf("%d %d\n", i, j);
      return 0;
    }
  for (int i = 1; i <= n; i++) flag[i] = 1;
  for (int i = 1; i <= n; i++)
    if (flag[i]) {
      flag[i] = 0;
      int p = 1;
      for (int q = a[i]; q != i; q = a[q]) {
        p++;
        flag[q] = 0;
      }
      if (p % 2 == 1) {
        puts("NO");
        return 0;
      }
      int now = i;
      for (int j = 1; j <= p; j++) {
        num[now] = p;
        now = a[now];
      }
    }
  int which = 0;
  for (int i = 1; i <= n; i++)
    if (num[i] == 2) {
      which = i;
      break;
    }
  if (which == 0) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = 1; i <= n; i++) flag[i] = 1;
  printf("%d %d\n", which, a[which]);
  flag[which] = 0;
  flag[a[which]] = 0;
  for (int i = 1; i <= n; i++)
    if (flag[i] == 1) {
      int p = which, q = i;
      for (int j = 1; j <= num[i]; j++) {
        flag[q] = 0;
        printf("%d %d\n", p, q);
        p = a[p];
        q = a[q];
      }
    }
  return 0;
}
