#include <bits/stdc++.h>
const int MOD = int(1e9) + 7;
inline int add(int a, int b) {
  return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline void inc(int &a, int b) { a = add(a, b); }
inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }
inline void dec(int &a, int b) { a = sub(a, b); }
inline int mul(int a, int b) { return (a * 1ll * b) % MOD; }
using namespace std;
const int N = 100000;
vector<pair<int, int> > vet;
vector<int> aux;
vector<vector<int> > cycles[N + 1];
int P[N];
bool vis[N];
void dfs(int u) {
  vis[u] = true;
  aux.push_back(u);
  u = P[u];
  if (!vis[u]) dfs(u);
}
void debug() {
  for (int i = 0; i <= N; i++)
    if (!cycles[i].empty()) {
      printf("%d: ", i);
      for (__typeof((cycles[i]).begin()) it = (cycles[i]).begin();
           it != (cycles[i]).end(); ++it) {
        printf("(");
        for (__typeof((*it).begin()) it2 = (*it).begin(); it2 != (*it).end();
             ++it2)
          printf("%d ", *it2);
        printf(") ");
      }
      puts("");
    }
}
bool solve(int testNumber) {
  int n;
  if (scanf("%d", &n) == EOF) return false;
  for (int i = 0; i < n; i++) {
    scanf("%d", &P[i]);
    P[i]--;
  }
  for (int i = 0; i <= N; i++) cycles[i].clear();
  vet.clear();
  for (int i = 0; i < N; i++) vis[i] = false;
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      aux.clear();
      dfs(i);
      cycles[((int)(aux).size())].push_back(aux);
    }
  for (int i = 0; i <= N; i++)
    for (int j = 1; j < ((int)(cycles[i]).size()); j++)
      for (int k = 0; k < i; k++)
        vet.push_back(make_pair((cycles[i][0][k]), (cycles[i][j][k])));
  for (int i = 0; i <= N; i++)
    if (!cycles[i].empty())
      for (int j = 1; j * j <= i; j++)
        if (i % j == 0) {
          if (j != i && !cycles[j].empty()) {
            for (int k = 0; k < i; k++)
              vet.push_back(
                  make_pair((cycles[j][0][k % j]), (cycles[i][0][k])));
            break;
          }
          int x = i / j;
          if (x != i && !cycles[x].empty()) {
            for (int k = 0; k < i; k++)
              vet.push_back(
                  make_pair((cycles[x][0][k % x]), (cycles[i][0][k])));
            break;
          }
        }
  if (cycles[1].empty() && !cycles[2].empty())
    vet.push_back(make_pair((cycles[2][0][0]), (cycles[2][0][1])));
  if (((int)(vet).size()) < n - 1)
    puts("NO");
  else {
    puts("YES");
    for (__typeof((vet).begin()) it = (vet).begin(); it != (vet).end(); ++it)
      printf("%d %d\n", it->first + 1, it->second + 1);
  }
  return true;
}
int main() {
  for (int i = 1; solve(i); i++)
    ;
  return 0;
}
