#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]), a[i]--;
  int only = -1, a1 = -1, a2 = -1;
  for (int i = 0; i < n; ++i)
    if (a[i] == i)
      only = i;
    else if (a[a[i]] == i)
      a1 = i, a2 = a[i];
  if (only != -1) {
    printf("YES\n");
    for (int i = 0; i < n; ++i)
      if (i != only) printf("%d %d\n", only + 1, i + 1);
  } else if (a1 != -1) {
    vector<pair<int, int> > res(1, make_pair(a1, a2));
    vector<bool> u(n);
    u[a1] = u[a2] = true;
    for (int i = 0; i < n; ++i)
      if (!u[i]) {
        int t = i;
        do {
          u[t] = true;
          res.push_back(make_pair(t, a1));
          swap(a1, a2);
          t = a[t];
        } while (t != i);
        if (a1 < a2) {
          printf("NO\n");
          return 0;
        }
      }
    printf("YES\n");
    for (int i = 0; i < res.size(); ++i)
      printf("%d %d\n", res[i].first + 1, res[i].second + 1);
  } else
    printf("NO\n");
  return 0;
}
