#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
bool get_cycle(vector<int>& permutation, vector<int>& used, int v,
               vector<int>& cycle);
enum STATUSES { FREE = 0, USED = 1, BUSY = 2 };
int main() {
  int n = 0;
  cin >> n;
  vector<int> permutation(n);
  int immovable = -1;
  for (int i = 0; i < n; i++) {
    cin >> permutation[i];
    permutation[i]--;
    if (i == permutation[i]) immovable = i;
  }
  if (immovable >= 0) {
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      if (i != immovable) cout << immovable + 1 << " " << i + 1 << "\n";
    }
    cin.get();
    cin.get();
    return 0;
  }
  vector<int> used(n, false);
  vector<vector<int> > cycles;
  for (int i = 0; i < n; i++) {
    if (used[i] == FREE) {
      vector<int> new_cycle;
      if (get_cycle(permutation, used, i, new_cycle))
        cycles.push_back(new_cycle);
    }
  }
  int two_cycle = -1;
  for (int i = 0; i < int(cycles.size()); i++) {
    if (cycles[i].size() == 2) two_cycle = i;
    if (cycles[i].size() % 2 != 0) {
      cout << "NO\n";
      return 0;
    }
  }
  if (two_cycle >= 0) {
    cout << "YES\n";
    for (int i = 0; i < int(cycles.size()); i++) {
      if (i == two_cycle) continue;
      for (int j = 0; j < int(cycles[i].size()); j++) {
        if (j % 2 == 0)
          cout << cycles[two_cycle][0] + 1 << " " << cycles[i][j] + 1 << "\n";
        else
          cout << cycles[two_cycle][1] + 1 << " " << cycles[i][j] + 1 << "\n";
      }
    }
    cout << cycles[two_cycle][0] + 1 << " " << cycles[two_cycle][1] + 1 << "\n";
  } else {
    cout << "NO\n";
  }
  cin.get();
  cin.get();
  return 0;
}
bool get_cycle(vector<int>& permutation, vector<int>& used, int v,
               vector<int>& cycle) {
  used[v] = BUSY;
  cycle.push_back(v);
  int next = permutation[v];
  if (used[next] == BUSY) {
    used[v] = USED;
    return true;
  } else if (used[next] == FREE) {
    bool is_cycle = get_cycle(permutation, used, next, cycle);
    used[v] = USED;
    if (is_cycle)
      return true;
    else
      return false;
  } else {
    used[v] = USED;
    return false;
  }
}
