#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &(n));
  vector<int> p(n);
  for (__typeof(n) i = 0; i < n; ++i) cin >> p[i], p[i]--;
  map<int, vector<int>> start;
  vector<bool> done(n);
  bool odds = false;
  for (__typeof(n) i = 0; i < n; ++i) {
    if (done[i]) continue;
    int j = i, len = 0;
    do {
      done[j] = true;
      len++;
      j = p[j];
    } while (j != i);
    if (len > 2 && (len & 1)) odds = true;
    start[len].push_back(i);
  }
  if (start.count(1)) {
    int center = start[1][0];
    cout << "YES" << endl;
    for (__typeof(n) i = 0; i < n; ++i)
      if (i != center) cout << center + 1 << " " << i + 1 << endl;
  } else if (start.count(2) && !odds) {
    int left = start[2][0], right = p[left];
    cout << "YES" << endl;
    cout << left + 1 << " " << right + 1 << endl;
    for (__typeof(n) i = 0; i < n; ++i) {
      if (!done[i] || i == left || i == right) continue;
      int j = i;
      do {
        cout << left + 1 << " " << j + 1 << endl;
        {
          left ^= right;
          right ^= left;
          left ^= right;
        };
        j = p[j];
        done[j] = false;
      } while (j != i);
    }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
