#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> p(n);
  vector<bool> used(n, false);
  vector<vector<int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  bool flag = true;
  int v;
  for (v = 0; v < n; v++)
    if (p[v] == v) {
      flag = false;
      break;
    }
  if (!flag) {
    cout << "YES" << endl;
    for (int i = 0; i < v; i++) cout << i + 1 << " " << v + 1 << endl;
    for (int i = v + 1; i < n; i++) cout << v + 1 << " " << i + 1 << endl;
    return 0;
  }
  int color = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      a[color].push_back(i);
      used[i] = true;
      int cur = p[i];
      while (cur != i) {
        a[color].push_back(cur);
        used[cur] = true;
        cur = p[cur];
      }
      color++;
    }
  }
  vector<pair<int, int> > size(color);
  for (int i = 0; i < color; i++) {
    size[i].first = a[i].size();
    size[i].second = i;
  }
  sort(size.begin(), size.end());
  if (size[0].first != 2) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 1; i < color; i++)
    if (size[i].first % 2 != 0) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
  for (int i = 0; i < size[0].first; i++) {
    cout << a[size[0].second][i] + 1 << " ";
  }
  cout << endl;
  for (int i = 1; i < color; i++) {
    for (int j = 0; j < size[i].first; j++) {
      int x = a[size[0].second][j % 2] + 1;
      int y = a[size[i].second][j] + 1;
      cout << x << " " << y << endl;
    }
  }
  return 0;
}
