#include <bits/stdc++.h>
using namespace std;
int vis[100010];
int a[100010];
int c[100010];
int d[100010];
set<int> b;
map<int, int> sum;
map<int, int> jt;
int main() {
  int n, x, i, j, cnt;
  while (scanf("%d", &n) != EOF) {
    b.clear();
    memset(vis, 0, sizeof(vis));
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i <= n; i++) {
      if (vis[i]) continue;
      vis[i] = 1;
      x = a[i];
      vis[x] = 1;
      cnt = 1;
      while (x != i) {
        cnt++;
        x = a[x];
        vis[x] = 1;
      }
      b.insert(cnt);
      sum[cnt]++;
      if (jt[cnt] == 0) {
        jt[cnt] = i;
        c[i] = 0;
      } else {
        c[i] = jt[cnt];
        jt[cnt] = i;
      }
    }
    x = 1;
    int ju = 0;
    set<int>::iterator it1 = b.begin();
    set<int>::iterator it2 = b.begin();
    cnt = *it1;
    if (cnt > 2)
      x = 0;
    else {
      for (it1++; it1 != b.end(); it1++) {
        ju = 0;
        i = *it1;
        for (it2 = b.begin(); *it2 < i; it2++) {
          j = *it2;
          if (i % j == 0) {
            d[i] = j;
            ju = 1;
            break;
          }
        }
        if (ju == 0) {
          x = 0;
          break;
        }
      }
    }
    if (x == 0) {
      printf("NO\n");
    } else {
      printf("YES\n");
      if (cnt == 1)
        cnt = jt[cnt];
      else {
        cnt = jt[cnt];
        i = a[cnt];
        printf("%d %d\n", cnt, i);
      }
      for (it1 = b.begin(); it1 != b.end(); it1++) {
        x = *it1;
        cnt = jt[x];
        if (it1 == b.begin())
          j = jt[x];
        else
          j = jt[d[x]];
        while (cnt != 0) {
          if (cnt == j) {
            cnt = c[cnt];
            continue;
          }
          printf("%d %d\n", cnt, j);
          i = a[cnt];
          j = a[j];
          while (i != cnt) {
            printf("%d %d\n", i, j);
            i = a[i];
            j = a[j];
          }
          cnt = c[cnt];
        }
      }
    }
  }
  return 0;
}
