#include <bits/stdc++.h>
using namespace std;
int perm[123456];
int n;
vector<vector<int> > cyc;
bool vis[123456];
bool cmp(const vector<int> &a, const vector<int> &b) {
  if (a.size() == b.size()) return a[0] < b[0];
  return a.size() < b.size();
}
void make_cycles() {
  vector<int> c;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    c.clear();
    c.push_back(i);
    vis[i] = 1;
    int j = perm[i];
    while (j != i) {
      c.push_back(j);
      vis[j] = 1;
      j = perm[j];
    }
    cyc.push_back(c);
  }
  sort(cyc.begin(), cyc.end(), cmp);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> perm[i];
  make_cycles();
  if (cyc[0].size() == 1) {
    cout << "YES\n";
    int c = cyc[0][0];
    for (int i = 1; i <= n; ++i)
      if (i != c) cout << c << " " << i << endl;
    return 0;
  }
  int odd = 0;
  for (int i = 0; i < cyc.size(); ++i)
    if (cyc[i].size() & 1) {
      odd = 1;
      break;
    }
  if (cyc[0].size() > 2 || odd) {
    cout << "NO\n";
    return 0;
  }
  int x = cyc[0][0];
  int y = cyc[0][1];
  cout << "YES\n";
  cout << x << " " << y << endl;
  for (int i = 1; i < cyc.size(); ++i) {
    for (int j = 0; j < cyc[i].size(); ++j) {
      if (j & 1) {
        cout << x << " " << cyc[i][j] << endl;
      } else {
        cout << y << " " << cyc[i][j] << endl;
      }
    }
  }
}
