#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
int n, cnt, one, two1, two2, p[nmax];
vector<int> v[nmax];
bitset<nmax> viz;
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++)
    if (!viz[i]) {
      cnt++;
      for (int j = i; !viz[j]; j = p[j]) {
        viz[j] = 1;
        v[cnt].push_back(j);
      }
    }
  for (int i = 1; i <= n; i++)
    if (v[i].size() == 1) {
      one = v[i][0];
      break;
    }
  if (one) {
    printf("YES\n");
    for (int i = 1; i <= n; i++)
      if (i != one) printf("%d %d\n", i, one);
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (v[i].size() == 2) {
      two1 = v[i][0];
      two2 = v[i][1];
      break;
    }
  if (two1) {
    for (int i = 1; i <= cnt; i++)
      if (v[i].size() & 1) {
        printf("NO\n");
        return 0;
      }
    printf("YES\n");
    printf("%d %d\n", two1, two2);
    for (int i = 1; i <= cnt; i++)
      if (v[i][0] != two1)
        for (int j = 0; j < (int)v[i].size(); j++) {
          if (j & 1)
            printf("%d %d\n", two1, v[i][j]);
          else
            printf("%d %d\n", two2, v[i][j]);
        }
    return 0;
  }
  printf("NO\n");
  return 0;
}
