#include <bits/stdc++.h>
using namespace std;
int A[152000];
int n;
bool visited[120000];
int go(int node) {
  if (visited[node]) return 0;
  visited[node] = true;
  return 1 + go(A[node]);
}
int pindex = -1;
int mini = 10;
int sindex = -1;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    --A[i];
  }
  bool impar = false;
  for (int i = 0; i < n; ++i) {
    if (visited[i] == false) {
      int l = go(i);
      if (l > 1 and l % 2 == 1) {
        impar = true;
      }
      if (l == 1) pindex = i;
      if (mini > l and l > 1) {
        mini = l;
        sindex = i;
      }
    }
  }
  if (pindex != -1) {
    cout << "YES" << endl;
    for (int i = 0; i < n; ++i)
      if (i != pindex) cout << pindex + 1 << " " << i + 1 << endl;
  } else if (!impar and mini == 2) {
    cout << "YES" << endl;
    memset(visited, 0, sizeof visited);
    cout << sindex + 1 << " " << A[sindex] + 1 << endl;
    visited[sindex] = visited[A[sindex]] = true;
    for (int i = 0; i < n; ++i)
      if (visited[i] == false) {
        int st = 0;
        int cur = i;
        while (true) {
          cout << (st ? (sindex + 1) : (A[sindex] + 1)) << " " << cur + 1
               << endl;
          st = 1 - st;
          visited[cur] = true;
          cur = A[cur];
          if (cur == i) break;
        }
      }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
