#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int x[maxn];
int m[maxn];
int n;
int tp1, tp2;
vector<int> v[2];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (int i = 1; i <= n; i++) {
    if (x[i] == i) tp1 = i;
    if (x[x[i]] == i) tp2 = i;
  }
  if (tp1) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (i != tp1) printf("%d %d\n", i, tp1);
    return 0;
  }
  if (tp2) {
    m[tp2] = m[x[tp2]] = 1;
    for (int i = 1; i <= n; i++) {
      if (m[i]) continue;
      v[0].push_back(i);
      m[i] = 1;
      int c = 1;
      int p = i;
      int to = 1;
      while (!m[x[p]]) {
        p = x[p];
        m[p] = 1;
        v[to].push_back(p);
        to ^= 1;
        c = c + 1;
      }
      if (c & 1) {
        puts("NO");
        return 0;
      }
    }
    puts("YES");
    printf("%d %d\n", tp2, x[tp2]);
    for (int i = 0; i < v[0].size(); i++) printf("%d %d\n", tp2, v[0][i]);
    for (int i = 0; i < v[1].size(); i++) printf("%d %d\n", x[tp2], v[1][i]);
    return 0;
  }
  puts("NO");
  return 0;
}
