#include <bits/stdc++.h>
using namespace std;
int n;
int p[123456];
vector<pair<int, int> > res;
bool visited[123456];
bool input() {
  if (cin >> n) {
    for (int i = (int)(0), _t = (int)(n - 1); i <= _t; i++) {
      cin >> p[i];
      --p[i];
    }
    return true;
  } else {
    return false;
  }
}
void solve() {
  for (int i = (int)(0), _t = (int)(n - 1); i <= _t; i++)
    if (p[i] == i) {
      cout << "YES" << endl;
      for (int j = (int)(0), _t = (int)(n - 1); j <= _t; j++)
        if (j != i) {
          cout << (i + 1) << " " << (j + 1) << endl;
        }
      return;
    }
  for (int i = (int)(0), _t = (int)(n - 1); i <= _t; i++)
    if (p[p[i]] == i) {
      res.clear();
      memset((visited), (false), sizeof(visited));
      int u = i, v = p[i];
      visited[u] = true, visited[v] = true;
      res.push_back(make_pair(u, v));
      for (int j = (int)(0), _t = (int)(n - 1); j <= _t; j++)
        if (!visited[j]) {
          int cnt = 0;
          int k = j;
          while (!visited[k]) {
            visited[k] = true;
            ++cnt;
            if (cnt % 2 == 0)
              res.push_back(make_pair(u, k));
            else
              res.push_back(make_pair(v, k));
            k = p[k];
          }
          if ((cnt % 2) != 0) {
            cout << "NO" << endl;
            return;
          }
        }
      cout << "YES" << endl;
      for (vector<pair<int, int> >::iterator pi = res.begin(); pi != res.end();
           pi++) {
        cout << (pi->first + 1) << " " << (pi->second + 1) << endl;
      }
      return;
    }
  cout << "NO" << endl;
}
int main() {
  while (input()) solve();
  return 0;
}
