#include <bits/stdc++.h>
using namespace std;
int n, P[1 << 20], V[1 << 20], connected[1 << 20];
set<int> G[1 << 20];
bool check(int a, int b) {
  a = P[a], b = P[b];
  return G[a].find(b) != G[a].end() || G[b].find(a) != G[b].end();
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", P + i), P[i]--;
  vector<int> C;
  for (int i = 0; i < (n); i++)
    if (V[i] == 0) {
      if (P[i] == i) {
        C.clear();
        C.push_back(i);
        V[i] = 1;
        continue;
      }
      int u = i, l = 0;
      while (!V[u]) {
        V[u] = 1;
        u = P[u];
        l++;
      }
      if (l == 2 && C.empty()) {
        C.push_back(i);
        C.push_back(P[i]);
      }
    }
  vector<pair<int, int> > E;
  if (C.size() == 0)
    puts("NO");
  else {
    int c1 = C[0], c2 = (C.size() == 1) ? c1 : C[1];
    if (C.size() == 2) E.push_back(make_pair(C[0], C[1])), G[C[0]].insert(C[1]);
    for (int i = 0; i < (n); i++)
      if (i != c1 && i != c2) {
        int u = i;
        while (!connected[u]) {
          connected[u] = 1;
          G[c1].insert(u);
          E.push_back(make_pair(c1, u));
          u = P[u];
          swap(c1, c2);
        }
      }
    if (E.size() != n - 1)
      puts("NO");
    else {
      for (auto e : E)
        if (!check(e.first, e.second)) {
          cerr << e.first << " " << e.second << endl;
          puts("NO");
          return 0;
        }
      puts("YES");
      for (auto e : E) printf("%d %d\n", e.first + 1, e.second + 1);
    }
  }
  return 0;
}
