#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
int p[maxn], vis[maxn];
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) {
    p[i] = read();
  }
  vector<vector<int> > res;
  vector<int> tmp;
  int tag1 = 0, tag2 = 1;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 1) continue;
    tmp.clear();
    int u = i;
    while (!vis[u]) {
      vis[u] = 1;
      tmp.push_back(u);
      u = p[u];
    }
    res.push_back(tmp);
    if (tmp.size() == 1) {
      int fa = tmp[0];
      printf("YES\n");
      for (int i = 1; i <= n; i++) {
        if (i == fa) continue;
        printf("%d %d\n", fa, i);
      }
      return 0;
    } else {
      if (tmp.size() == 2) {
        tag1 = 1;
      } else {
        int c = tmp.size();
        if (c & 1) tag2 = 0;
      }
    }
  }
  if (tag1 == 1 && tag2 == 1) {
    for (int i = 0; i < res.size(); i++) {
      if (res[i].size() != 2) continue;
      tmp = res[i];
      int u = tmp[0], v = tmp[1], cur = 1;
      printf("YES\n");
      printf("%d %d\n", u, v);
      for (int j = 0; j < res.size(); j++) {
        if (i == j) continue;
        tmp = res[j];
        for (int k = 0; k < tmp.size(); k++) {
          printf("%d %d\n", cur == 1 ? u : v, tmp[k]);
          cur ^= 1;
        }
      }
      return 0;
    }
  } else {
    printf("NO\n");
  }
  return 0;
}
