#include <bits/stdc++.h>
using namespace std;
pair<int, int> ans[100005];
int l[100005], p[100005], vis[100005];
int len, anslen;
vector<int> cc[100005];
bool solve() {
  int i, j, k;
  int single = -1, odd = 0, even = -1;
  for (i = 0; i < len; ++i) vis[i] = 0, l[i] = 0;
  for (i = 0; i < len; ++i)
    if (!vis[i]) {
      for (j = i, k = 0; !vis[j]; j = p[j]) vis[j] = 1, ++k;
      for (j = i; !l[j]; j = p[j]) l[j] = k;
      if (k == 1)
        single = i;
      else if (k % 2 != 0)
        odd = 1;
      else if (k == 2)
        even = i;
    }
  anslen = 0;
  if (single >= 0) {
    for (i = 0; i < len; ++i)
      if (i != single) ans[anslen++] = pair<int, int>(single, i);
    return 1;
  } else if (odd) {
    return 0;
  } else if (even != -1) {
    for (i = 0; i < len; ++i) vis[i] = 0;
    vis[even] = vis[p[even]] = 1;
    ans[anslen++] = pair<int, int>(even, p[even]);
    for (i = 0; i < len; ++i)
      if (!vis[i]) {
        for (j = i, k = 0; !vis[j]; j = p[j])
          vis[j] = 1, ans[anslen++] = pair<int, int>(j, k % 2 ? even : p[even]),
          ++k;
      }
    return 1;
  } else
    return 0;
}
int main() {
  int i;
  while (scanf("%d", &len) == 1) {
    for (i = 0; i < len; ++i) scanf("%d", &p[i]), --p[i];
    if (solve()) {
      printf("YES\n");
      for (i = 0; i < anslen; ++i)
        printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
    } else
      puts("NO");
  }
  return 0;
}
