#include <bits/stdc++.h>
using namespace std;
int P[210000], n, pos1 = -1, pos2 = -1;
vector<int> ring[210000];
int tot = 0;
bool vis[210000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &P[i]);
  for (int i = 1; i <= n; i++) {
    if (P[i] == i) pos1 = i;
    if (P[P[i]] == i) pos2 = i;
  }
  if (pos1 == -1 && pos2 == -1) {
    printf("NO\n");
    return 0;
  }
  if (pos1 != -1) {
    printf("YES\n");
    for (int i = 1; i <= n; i++)
      if (i != pos1) printf("%d %d\n", i, pos1);
  } else {
    for (int i = 1; i <= n; i++) {
      if (!vis[i] && i != pos2 && i != P[pos2]) {
        int p = i;
        tot++;
        while (!vis[p]) {
          vis[p] = true;
          ring[tot].push_back(p);
          p = P[p];
        }
      }
    }
    for (int i = 1; i <= tot; i++)
      if (ring[i].size() % 2) {
        printf("NO\n");
        return 0;
      }
    printf("YES\n");
    printf("%d %d\n", pos2, P[pos2]);
    for (int i = 1; i <= tot; i++) {
      for (int j = 0; j < ring[i].size(); j++) {
        if (j & 1)
          printf("%d %d\n", ring[i][j], pos2);
        else
          printf("%d %d\n", ring[i][j], P[pos2]);
      }
    }
  }
  return 0;
}
