#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
int ar[100005];
bool visited[100005];
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 1; i <= n; ++i) scanf("%d", &ar[i]);
  memset(visited, false, sizeof(visited));
  vector<vector<int> > cycles;
  for (i = 1; i <= n; ++i) {
    if (!visited[i]) {
      vector<int> v;
      int st = i;
      while (!visited[i]) {
        st = ar[st];
        visited[st] = true;
        v.push_back(st);
      }
      cycles.push_back(v);
    }
  }
  vector<int> ans;
  int flag = 0;
  for (i = 0; i <= (int)(cycles.size() - 1); ++i) {
    int sz = cycles[i].size();
    if (sz == 1 || sz == 2) {
      ans = cycles[i];
      flag = i + 1;
      if (sz == 1) break;
    }
  }
  if (!flag)
    printf("NO\n");
  else {
    flag--;
    vector<pair<int, int> > edges;
    for (i = 0; i <= (int)(cycles.size() - 1); ++i) {
      if (i != flag) {
        int sz = ans.size();
        if (sz == 1) {
          int nd = ans[0];
          for (j = 0; j <= (int)(cycles[i].size() - 1); ++j) {
            int x = cycles[i][j];
            edges.push_back(make_pair(nd, x));
          }
        } else {
          int nd = ans[0];
          int nd2 = ans[1];
          int xr = 0;
          if (cycles[i].size() & 1) {
            cout << "NO\n";
            return 0;
          }
          for (j = 0; j <= (int)(cycles[i].size() - 1); ++j) {
            xr ^= 1;
            int x = cycles[i][j];
            if (xr)
              edges.push_back(make_pair(nd, x));
            else
              edges.push_back(make_pair(nd2, x));
          }
        }
      }
    }
    if ((int)(ans.size()) == 2) edges.push_back(make_pair(ans[0], ans[1]));
    printf("YES\n");
    for (i = 0; i <= (int)(edges.size() - 1); ++i)
      cout << edges[i].first << " " << edges[i].second << endl;
  }
  return 0;
}
