#include <bits/stdc++.h>
using namespace std;
int n, p[100100], root;
bitset<100100> visited;
vector<vector<int> > r(100100);
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      int u = i, o = 1;
      while (true) {
        visited[u] = true;
        u = p[u];
        if (u == i)
          break;
        else
          o++;
      }
      r[o].push_back(u);
    }
  }
  bool possible = false;
  if (!r[1].empty()) {
    possible = true;
    root = r[1][0];
    swap(r[1][0], r[1][r[1].size() - 1]);
    r[1].pop_back();
  } else {
    if (!r[2].empty()) {
      bool aux = true;
      for (int i = 0; i <= n; i++)
        if (i % 2 == 1 && !r[i].empty()) aux = false;
      if (aux) {
        possible = true;
        root = r[2][0];
        swap(r[2][0], r[2][r[2].size() - 1]);
        r[2].pop_back();
      }
    }
  }
  if (possible) {
    printf("YES\n");
    for (int i = 1; i <= n; i++)
      if (!r[i].empty()) {
        int root_aux = root;
        for (int j = 0; j < (int)r[i].size(); j++) {
          for (int k = 0; k < i; k++) {
            printf("%d %d\n", root_aux, r[i][j]);
            root_aux = p[root_aux];
            r[i][j] = p[r[i][j]];
          }
        }
      }
    if (p[root] != root) printf("%d %d\n", root, p[root]);
  } else
    printf("NO\n");
}
