#include <bits/stdc++.h>
using namespace std;
vector<int> a[100100];
int x[100100];
bool vis[100100];
int b[100100], pre[100100];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", x + i);
  int tot = 0;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int u = i, cnt = 0;
      while (!vis[u]) {
        vis[u] = true;
        u = x[u];
        ++cnt;
      }
      u = i;
      do {
        a[cnt].push_back(u);
        u = x[u];
      } while (u != i);
      b[tot++] = cnt;
    }
  sort(b, b + tot);
  tot = unique(b, b + tot) - b;
  if (b[0] > 2) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= tot - 1; ++i) {
    bool flag = false;
    for (int j = 0; j < i; ++j)
      if (b[i] % b[j] == 0) {
        flag = true;
        pre[i] = b[j];
        break;
      }
    if (!flag) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  for (int i = 0; i < tot; ++i) {
    for (int j = b[i]; j < a[b[i]].size(); ++j)
      printf("%d %d\n", a[b[i]][j], a[b[i]][j - b[i]]);
    if (i)
      for (int j = 0; j < b[i]; ++j)
        printf("%d %d\n", a[b[i]][j], a[pre[i]][j % pre[i]]);
  }
  if (b[0] == 2) printf("%d %d\n", a[2][0], a[2][1]);
  return 0;
}
