#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 1e6 + 5;
long long int t, n, m, a[N], vis[N];
vector<pair<long long int, long long int> > edges;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, x, y;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i) {
      cout << "YES\n";
      for (j = 1; j <= n; j++) {
        if (j == i) continue;
        cout << i << " " << j << '\n';
      }
      return 0;
    }
  }
  x = -1;
  y = -1;
  for (i = 1; i <= n; i++) {
    if (a[a[i]] == i) {
      x = i;
      y = a[i];
    }
  }
  if (x == -1) {
    cout << "NO";
    return 0;
  }
  vis[x] = vis[y] = 1;
  edges.push_back({x, y});
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    long long int cc = 0;
    m = i;
    while (1) {
      vis[m] = 1;
      if (cc % 2 == 0)
        edges.push_back({m, x});
      else
        edges.push_back({m, y});
      cc++;
      m = a[m];
      if (m == i) break;
    }
    if (cc % 2) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES\n";
  for (auto it : edges) cout << it.first << " " << it.second << '\n';
  return 0;
}
