#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 100000000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;
double sqr(double first) { return first * first; };
long double sqr(long double first) { return first * first; };
long long sqr(long long first) { return first * first; };
long long sqr(int first) { return first * 1LL * first; };
long long bpm(long long a, long long n = -2, long long m = mod) {
  n = n >= 0 ? n : m + n;
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % m;
    a = (a * a) % m;
    n >>= 1;
  }
  return r;
}
const int N = 100002;
int p[N], u[N];
vector<int> c[N];
int main(int argc, char* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  int ch = 0;
  for (int i = 1; i <= n; i++)
    if (!u[i]) {
      for (int first = p[i]; !u[first]; first = p[first])
        u[first] = true, c[ch].push_back(first);
      ch++;
    }
  sort(c, c + ch, [](const vector<int>& a, const vector<int>& b) {
    return a.size() < b.size();
  });
  if (c[0].size() == 1) {
    cout << "YES\n";
    int first = c[0][0];
    for (int i = 1; i <= n; i++)
      if (i != first) cout << first << " " << i << "\n";
    return 0;
  } else if (c[0].size() == 2) {
    bool second = false;
    for (int i = 0; i < ch; i++) second |= c[i].size() % 2;
    if (!second) {
      cout << "YES\n";
      int f = c[0][0], s = c[0][1];
      cout << f << " " << s << endl;
      for (int i = 0; i < ch; i++)
        for (int first : c[i])
          if (first != f && first != s) {
            cout << f << " " << first << endl;
            swap(f, s);
          }
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
