#include <bits/stdc++.h>
using namespace std;
vector<int> ciclu[100010];
int v[100010];
char vaz[100010];
int main() {
  int n, nr = 0, minn = 1000000000, poz;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= n; i++)
    if (!vaz[i]) {
      nr++;
      int a = i;
      do {
        ciclu[nr].push_back(a);
        vaz[a] = 1;
        a = v[a];
      } while (a != i);
      if (ciclu[nr].size() < minn) {
        minn = ciclu[nr].size();
        poz = nr;
      }
    }
  swap(ciclu[1], ciclu[poz]);
  if (ciclu[1].size() == 1) {
    printf("YES\n");
    for (int i = 1; i <= n; i++)
      if (i != ciclu[1][0]) printf("%d %d\n", ciclu[1][0], i);
    return 0;
  } else if (ciclu[1].size() > 2) {
    printf("NO");
    return 0;
  }
  for (int i = 1; i <= nr; i++)
    if (ciclu[i].size() % 2) {
      printf("NO");
      return 0;
    }
  printf("YES\n");
  printf("%d %d\n", ciclu[1][0], ciclu[1][1]);
  for (int i = 2; i <= nr; i++)
    for (int j = 0; j < ciclu[i].size(); j++)
      printf("%d %d\n", ciclu[1][j % 2], ciclu[i][j]);
  return 0;
}
