#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
const int maxn = 200000;
int p[maxn], vis[maxn], id[maxn], N;
vector<int> C[maxn];
int main() {
  int large = 0, small = 0;
  scanf("%d", &N);
  for (int i = (1); i <= (N); ++i) scanf("%d", &p[i]);
  for (int i = (1); i <= (N); ++i)
    if (!vis[i]) {
      vis[i] = 1;
      C[i].push_back(i);
      for (int j = p[i]; j != i; j = p[j]) vis[j] = 1, C[i].push_back(j);
      if (C[i].size() == 1)
        ++small;
      else if (C[i].size() == 2)
        ++large;
    }
  for (int i = (1); i <= (N); ++i)
    if (C[i].size() > 2 && (C[i].size() % 2 == 0) && !small && !large) {
      puts("NO");
      return 0;
    } else if (C[i].size() > 2 && (C[i].size() & 1) && !small) {
      puts("NO");
      return 0;
    }
  puts("YES");
  int flag = 0;
  int rt = 0;
  for (int i = (1); i <= (N); ++i)
    if (C[i].size() == 1) {
      if (!rt)
        rt = i;
      else
        printf("%d %d\n", rt, i), rt = i;
    }
  for (int i = (1); i <= (N); ++i)
    if (C[i].size() == 2) {
      if (!flag) {
        if (rt)
          printf("%d %d\n%d %d\n", rt, C[i][0], rt, C[i][1]);
        else
          printf("%d %d\n", C[i][0], C[i][1]);
        for (int k = (0); k <= (1); ++k) id[k] = C[i][k];
        flag = 1;
      } else
        for (int k = (0); k <= (1); ++k) printf("%d %d\n", id[k], C[i][k]);
    }
  for (int i = (1); i <= (N); ++i)
    if (C[i].size() > 2) {
      if (rt) {
        for (int j = (0); j < (C[i].size()); ++j)
          printf("%d %d\n", rt, C[i][j]);
      } else
        for (int j = (0); j < (C[i].size()); ++j)
          printf("%d %d\n", id[j & 1], C[i][j]);
    }
  return 0;
}
