#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int maxn = 100000 + 100;
int p[maxn];
bool was[maxn];
bool dfs(int v, int len) {
  was[v] = true;
  if (!was[p[v - 1]])
    return dfs(p[v - 1], len + 1);
  else
    return len % 2 == 0;
}
void dfs2(int c, int l, int r, int idx) {
  was[c] = true;
  if (idx == 0)
    cout << c << " " << l << '\n';
  else
    cout << c << " " << r << '\n';
  if (!was[p[c - 1]]) dfs2(p[c - 1], l, r, 1 - idx);
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> p[i];
  for (int i = 0; i < (n); i++)
    if (p[i] == i + 1) {
      cout << "YES" << '\n';
      for (int j = 0; j < (n); j++) {
        if (i != j) cout << i + 1 << " " << j + 1 << '\n';
      }
      return 0;
    }
  for (int i = 0; i < (n); i++)
    if (p[p[i] - 1] == i + 1) {
      int l = i + 1;
      int r = p[i];
      memset(was, 0, sizeof(was));
      for (int j = 0; j < (n); j++)
        if (j + 1 != l && j + 1 != r && !was[j + 1])
          if (!dfs(j + 1, 1)) {
            cout << "NO" << '\n';
            return 0;
          }
      memset(was, 0, sizeof(was));
      cout << "YES" << '\n';
      cout << l << " " << r << '\n';
      for (int j = 0; j < (n); j++)
        if (j + 1 != l && j + 1 != r && !was[j + 1]) dfs2(j + 1, l, r, 0);
      return 0;
    }
  cout << "NO" << '\n';
  return 0;
}
