#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007, N = 100000, M = 1000;
int n, a[105000];
bool used[105000];
void solve1(int id) {
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    if (i != id) cout << i << " " << id << endl;
  }
  exit(0);
}
vector<int> first, second;
void solve2(int id) {
  int l = id, r = a[id];
  used[l] = used[r] = 1;
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      bool turn = 1;
      int j = i;
      while (!used[j]) {
        used[j] = 1;
        if (!turn)
          second.push_back(j);
        else
          first.push_back(j);
        j = a[j];
        turn ^= 1;
      }
      if (!turn) return;
    }
  }
  cout << "YES\n";
  cout << l << " " << r << endl;
  for (int i = 0; i < first.size(); i++) cout << l << " " << first[i] << endl;
  for (int i = 0; i < second.size(); i++) cout << r << " " << second[i] << endl;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) {
      solve1(i);
      break;
    }
  }
  for (int i = 1; i <= n; i++)
    if (i == a[a[i]]) {
      solve2(i);
      break;
    }
  cout << "NO";
  return 0;
}
