#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long INF = 1LL << 62;
const long long MINF = -(1LL << 62);
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
vector<vector<int>> cycs[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<int> volt(n + 1);
  bool have_odd = false;
  for (int i = 0; i < n; ++i) {
    if (!volt[p[i]]) {
      vector<int> cyc;
      int akt = p[i];
      while (!volt[akt]) {
        cyc.push_back(akt);
        volt[akt] = 1;
        akt = p[akt - 1];
      }
      cycs[(int)(cyc).size()].push_back(cyc);
      have_odd |= (int)(cyc).size() & 1;
    }
  }
  if (!cycs[1].empty()) {
    cout << "YES\n";
    for (int i = 1; i <= n; ++i) {
      if (cycs[1][0][0] != i) cout << cycs[1][0][0] << " " << i << "\n";
    }
    return 0;
  }
  if (cycs[2].empty() || have_odd) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  vector<int> base = cycs[2][0];
  cout << base[0] << " " << base[1] << "\n";
  for (int i = 2; i <= n; ++i) {
    for (auto j : cycs[i]) {
      if (i == 2 && j == base) continue;
      for (int k = 0; k < (int)(j).size(); ++k) {
        cout << base[k % 2] << " " << j[k] << "\n";
      }
    }
  }
  return 0;
}
