#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100009;
vector<int> a;
vector<int> color(MaxN, 0);
vector<int> paint(MaxN, 0);
vector<pair<int, int> > z;
int dfs(int v) {
  color[v] = 1;
  if (!color[a[v]]) return dfs(a[v]) + 1;
  color[v] = 2;
  return 1;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    b--;
    a.push_back(b);
  }
  for (int i = 0; i < n; i++) {
    if (!color[i]) z.push_back(make_pair(dfs(i), i));
  }
  int Min = MaxN;
  int u = -1;
  for (int i = 0; i < z.size(); i++) {
    if (Min > z[i].first) {
      Min = z[i].first;
      u = i;
    }
  }
  bool t = true;
  for (int i = 0; i < z.size(); i++) {
    if (z[i].first % Min != 0) t = false;
  }
  if (!t || (Min != 2 && Min != 1)) {
    cout << "NO";
  } else {
    cout << "YES" << endl;
    if (Min != 1) cout << z[u].second + 1 << " " << a[z[u].second] + 1 << endl;
    for (int i = 0; i < z.size(); i++) {
      if (u != i) {
        for (int j = 0, r = z[i].second, t = z[u].second; j < z[i].first;
             j++, t = a[t], r = a[r]) {
          cout << r + 1 << " " << t + 1 << endl;
        }
      }
    }
  }
  return 0;
}
