#include <bits/stdc++.h>
using namespace std;
int n, p[200000], num[200000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) {
    if (i == p[i]) {
      puts("YES");
      for (int j = 1; j <= n; j++)
        if (j != i) printf("%d %d\n", j, i);
      return 0;
    }
  }
  int pos = 0;
  for (int i = 1; i <= n; i++)
    if (!num[i]) {
      int cnt = 1, now = p[i];
      while (now != i) cnt++, now = p[now];
      num[i] = cnt;
      now = p[i];
      while (now != i) num[now] = cnt, now = p[now];
      if (cnt == 2) pos = i;
      if (cnt % 2 == 1) return puts("NO"), 0;
    }
  if (!pos)
    puts("NO");
  else {
    puts("YES");
    memset(num, 0, sizeof num);
    num[pos] = num[p[pos]] = 2;
    printf("%d %d\n", pos, p[pos]);
    for (int i = 1; i <= n; i++)
      if (!num[i]) {
        printf("%d %d\n", i, pos);
        int now = p[i], cnt = 1;
        while (now != i) {
          printf("%d %d\n", now, cnt ? p[pos] : pos);
          cnt ^= 1;
          now = p[now];
        }
        now = p[i];
        num[i] = 1;
        while (now != i) num[now] = 1, now = p[now];
      }
  }
}
