#include <bits/stdc++.h>
using namespace std;
int n, p[100000];
vector<bool> explr;
vector<int> getCycle(int pos) {
  vector<int> ret;
  while (!explr[pos]) {
    ret.push_back(pos);
    explr[pos] = true;
    pos = p[pos];
  }
  return ret;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  explr.resize(n, false);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  pair<size_t, size_t> shortest = make_pair(n + 1, 0);
  vector<vector<int> > cycles;
  for (int i = 0; i < n; i++)
    if (!explr[i]) {
      cycles.push_back(getCycle(i));
      shortest =
          min(shortest, make_pair(cycles.back().size(), cycles.size() - 1));
    }
  vector<pair<int, int> > edge;
  if (shortest.first > 2) {
    cout << "NO\n";
    return 0;
  }
  size_t sind = shortest.second;
  for (size_t i = 0; i < cycles.size(); i++)
    if (i != sind) {
      if (shortest.first == 2 && cycles[i].size() % 2 == 1) {
        cout << "NO\n";
        return 0;
      }
      for (size_t j = 0; j < cycles[i].size(); j++)
        edge.push_back(
            make_pair(cycles[sind][j % shortest.first], cycles[i][j]));
    }
  if (shortest.first == 2) {
    edge.push_back(make_pair(cycles[sind][0], cycles[sind][1]));
  }
  cout << "YES\n";
  for (auto e : edge) cout << e.first + 1 << ' ' << e.second + 1 << '\n';
  return 0;
}
