#include <bits/stdc++.h>
using namespace std;
bool ok[100005];
int main() {
  int n;
  scanf("%d", &n);
  int p[n + 5];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  bool ada = false;
  vector<pair<int, int> > edge;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      ada = true;
      for (int j = 1; j <= n; j++) {
        if (i != j) edge.push_back(make_pair(i, j));
      }
      break;
    }
  }
  if (!ada) {
    for (int i = 1; i <= n; i++) {
      if (p[p[i]] == i) {
        ada = true;
        edge.push_back(make_pair(p[i], i));
        ok[p[i]] = ok[i] = true;
        int lola = i;
        int lolb = p[i];
        for (int j = 1; j <= n; j++) {
          if (ok[j]) continue;
          int temp = 1;
          int now = j;
          int next = p[now];
          while (next != j) {
            next = p[next];
            temp++;
          }
          bool lol = true;
          if (temp % 2 == 0) {
            now = j;
            while (true) {
              if (ok[now]) break;
              ok[now] = true;
              int lel;
              if (lol)
                lel = lola;
              else
                lel = lolb;
              edge.push_back(make_pair(lel, now));
              lol = !lol;
              now = p[now];
            }
          } else {
            ada = false;
            break;
          }
        }
        break;
      }
    }
  }
  if (!ada)
    printf("NO\n");
  else {
    printf("YES\n");
    for (int i = 0; i < edge.size(); i++)
      printf("%d %d\n", edge[i].first, edge[i].second);
  }
  return 0;
}
