#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  while (b != 0) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m = 0, j, k;
  cin >> n;
  vector<int> x(n + 1);
  vector<bool> y(n + 1);
  vector<vector<int>> z;
  vector<pair<int, int>> h;
  pair<int, int> p;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    y[i] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (!y[i]) continue;
    z.push_back(vector<int>());
    z[m].push_back(i);
    j = x[i];
    while (j != i) {
      y[j] = false;
      z[m].push_back(j);
      j = x[j];
    }
    y[i] = false;
    p.first = z[m].size();
    p.second = m;
    h.push_back(p);
    m++;
  }
  sort(h.begin(), h.end());
  int q = h[0].first;
  for (int i = 1; i < m; i++) {
    q = gcd(q, h[i].first);
  }
  if ((q > 2) || ((q == 1) && (h[0].first != 1)) || (h[0].first > 2)) {
    cout << "NO";
    return 0;
  }
  cout << "YES" << endl;
  k = h[0].second;
  if (q == 2) {
    cout << z[k][0] << " " << z[k][1] << endl;
  }
  for (int i = 1; i < m; i++) {
    j = h[i].second;
    int a = z[j][0], b = z[k][0];
    int c, d;
    c = d = 1;
    if (c == z[j].size()) c = 0;
    if (d == z[k].size()) d = 0;
    cout << a << " " << b << endl;
    while ((z[j][c] != a) || (z[k][d] != b)) {
      cout << z[j][c] << " " << z[k][d] << endl;
      c++;
      if (c == z[j].size()) c = 0;
      d++;
      if (d == z[k].size()) d = 0;
    }
  }
  return 0;
}
