#include <bits/stdc++.h>
using namespace std;
struct P {
  int num, top;
} p[1000050];
vector<P> v;
bool is[1000050];
int a[1000050], n;
bool cmp(P a, P b) { return a.num < b.num; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (is[i]) continue;
    int t = i;
    int k = 1;
    while (a[t] != i) {
      is[t] = 1;
      t = a[t];
      k++;
    }
    is[t] = 1;
    p[cnt].num = k;
    p[cnt].top = i;
    cnt++;
  }
  sort(p, p + cnt, cmp);
  if (p[0].num == 1) {
    puts("YES");
    for (int i = 1; i <= n; i++) {
      if (i == p[0].top) continue;
      printf("%d %d\n", p[0].top, i);
    }
    return 0;
  }
  P t;
  if (p[0].num != 2) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i < cnt; i++) {
    if (p[i].num % 2 == 0) {
      t.num = p[0].top;
      t.top = p[i].top;
      v.push_back(t);
      t.num = a[t.num];
      t.top = a[t.top];
      while (t.num != p[0].top || t.top != p[i].top) {
        v.push_back(t);
        t.num = a[t.num];
        t.top = a[t.top];
      }
    } else {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  printf("%d %d\n", p[0].top, a[p[0].top]);
  for (int i = 0; i < v.size(); i++) {
    printf("%d %d\n", v[i].num, v[i].top);
  }
}
