#include <bits/stdc++.h>
using namespace std;
const int Maxn = 110000;
vector<int> same[Maxn];
int tot = 0;
bool vis[Maxn];
int p[Maxn];
vector<int> get(int x) {
  vector<int> ret;
  while (!vis[x]) {
    ret.push_back(x);
    vis[x] = true;
    x = p[x];
  }
  return ret;
}
bool cmp(const vector<int> &a, const vector<int> &b) {
  return a.size() < b.size();
}
vector<vector<int> > stage[Maxn];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> p[i];
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      same[tot++] = (get(i));
    }
  }
  sort(same, same + tot, cmp);
  if (same[0].size() != 1) {
    if (same[0].size() > 2) {
      cout << "NO" << endl;
      return 0;
    } else {
      for (int j = 0; j < tot; ++j)
        if (same[j].size() % 2) {
          cout << "NO" << endl;
          return 0;
        }
      cout << "YES" << endl;
      cout << same[0][1] << " " << same[0][0] << endl;
      int cnt = 0;
      for (int j = 1; j < tot; ++j) {
        for (int k = 0; k < (int)same[j].size(); ++k) {
          if (cnt % 2)
            cout << same[0][1] << " " << same[j][k] << endl;
          else
            cout << same[0][0] << " " << same[j][k] << endl;
          cnt++;
        }
      }
    }
  } else {
    cout << "YES" << endl;
    for (int j = 1; j < tot; ++j) {
      for (int k = 0; k < (int)same[j].size(); ++k)
        cout << same[0][0] << " " << same[j][k] << endl;
    }
  }
  return 0;
}
