#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
bool used[123456];
bool cmp(const vector<int>& a, const vector<int>& b) {
  return a.size() < b.size();
}
int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; ++i) cin >> p[i];
  vector<vector<int> > circle;
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      used[i] = 1;
      int curi = i;
      circle.push_back(vector<int>(1, i));
      while (!used[p[curi]]) {
        curi = p[curi];
        circle.back().push_back(curi);
        used[curi] = true;
      }
    }
  }
  bool ok = false;
  for (int i = 0; i < circle.size(); ++i)
    ok |= (circle[i].size() == 2 || circle[i].size() == 1);
  if (!ok) {
    cout << "NO";
    return 0;
  }
  sort(circle.begin(), circle.end(), cmp);
  if (circle[0].size() == 1) {
    cout << "YES\n";
    for (int i = 1; i < circle.size(); ++i)
      for (int j = 0; j < circle[i].size(); ++j)
        cout << circle[0][0] << " " << circle[i][j] << "\n";
    return 0;
  }
  for (int i = 0; i < circle.size(); ++i) {
    if (circle[i].size() % 2 != 0) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES\n";
  cout << circle[0][1] << " " << circle[0][0] << "\n";
  for (int i = 1; i < circle.size(); ++i)
    for (int j = 0; j < circle[i].size(); ++j)
      cout << circle[0][j % 2] << " " << circle[i][j] << "\n";
}
