#include <bits/stdc++.h>
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const long long INF64 = (long long)2e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = std::acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
  T X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
const int MAXN = 100005;
const int MAXV = 1 << 20;
int n, m, k;
int dr[4] = {0, 1, 0, -1};
int dc[4] = {-1, 0, 1, 0};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char S[MAXN];
int to[MAXN];
bool vis[MAXN];
std::vector<int> cycle[MAXN];
int dfs(int u, int p) {
  cycle[p].push_back(u);
  vis[u] = true;
  if (vis[to[u]]) return 1;
  return dfs(to[u], p) + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    to[i] = read<int>();
  }
  std::vector<std::pair<int, int>> cycles;
  bool cycle3 = false;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      int x = dfs(i, i);
      cycles.push_back({x, i});
      if (x >= 3 && x & 1) cycle3 = true;
      if (x == n && n >= 3) {
        printf("NO\n");
        return 0;
      }
    }
  }
  std::sort(cycles.begin(), cycles.end());
  if (cycles[0].first > 2 || (cycles[0].first == 2 && cycle3)) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  int first = cycles[0].second;
  if (cycle[first].size() == 1) {
    for (auto a : cycles) {
      if (a.second == first) continue;
      for (auto v : cycle[a.second]) {
        printf("%d %d\n", cycle[first][0], v);
      }
    }
  } else {
    printf("%d %d\n", cycle[first][0], cycle[first][1]);
    for (auto a : cycles) {
      if (a.second == first) continue;
      int x = 0;
      for (auto v : cycle[a.second]) {
        printf("%d %d\n", cycle[first][x % 2], v);
        x++;
      }
    }
  }
  return 0;
}
