#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, cnt, cou;
int num[100010], vis[100010], size[100010];
vector<int> v[100010];
void dfs(int u) {
  if (vis[u]) {
    return;
  }
  v[cnt].push_back(u);
  cou++;
  vis[u] = 1;
  dfs(num[u]);
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num[i]);
    }
    cnt = cou = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        size[cnt] = cou;
        cnt++;
        cou = 0;
      }
    }
    int min1 = 99999999, pos;
    for (int i = 0; i < cnt; i++) {
      if (min1 > size[i]) {
        min1 = size[i];
        pos = i;
      }
    }
    if (min1 > 2) {
      printf("NO\n");
      continue;
    }
    int flag = 0;
    if (min1 != 1) {
      for (int i = 0; i < cnt; i++) {
        if (size[i] % min1 != 0) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    if (min1 == 1) {
      int re = v[pos][0];
      for (int i = 0; i < cnt; i++) {
        if (i == pos) {
          continue;
        }
        for (int j = 0; j < size[i]; j++) {
          printf("%d %d\n", re, v[i][j]);
        }
      }
    } else {
      printf("%d %d\n", v[pos][0], v[pos][1]);
      for (int i = 0; i < cnt; i++) {
        if (i == pos) continue;
        for (int j = 0; j < size[i]; j++) {
          if (j & 1) {
            printf("%d %d\n", v[pos][0], v[i][j]);
          } else {
            printf("%d %d\n", v[pos][1], v[i][j]);
          }
        }
      }
    }
  }
  return 0;
}
