#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> ar(n + 1);
  for (int i = 1; i <= n; i++) scanf("%d", &ar[i]);
  vector<int> visited(n + 1, 0);
  vector<vector<int> > chains;
  int flag = -1;
  for (int i = 1; i <= n; i++) {
    if (ar[i] == i) {
      flag = i;
      break;
    }
  }
  if (flag != -1) {
    printf("YES\n");
    for (int i = 1; i <= n; i++) {
      if (i == flag) continue;
      printf("%d %d\n", flag, i);
    }
    return 0;
  }
  bool found = false;
  int pos2 = -1;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      vector<int> vec;
      int x = i;
      do {
        vec.push_back(ar[x]);
        visited[x] = 1;
        x = ar[x];
      } while (visited[x] == 0);
      if (vec.size() % 2 == 1) {
        cout << "NO";
        return 0;
      }
      if (found == false && vec.size() == 2) {
        pos2 = i;
      }
      if (vec.size() > 2 || found == true) chains.push_back(vec);
      if (pos2 != -1) found = true;
    }
  }
  if (pos2 == -1) {
    cout << "NO";
    return 0;
  }
  printf("YES\n");
  int dp[2];
  dp[0] = pos2;
  dp[1] = ar[pos2];
  for (int i = 0; i < chains.size(); i++) {
    int z = 0;
    for (int j = 0; j < chains[i].size(); j++) {
      z = z ^ 1;
      printf("%d %d\n", dp[z], chains[i][j]);
    }
  }
  printf("%d %d\n", dp[0], dp[1]);
  return 0;
}
