#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 10;
const int maxn5 = 3 * 1000 * 100 + 10;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;
int perm[maxn5];
bool mark[maxn5], turn[maxn5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> perm[i];
  int v = 0;
  for (int i = 1; i <= n; i++)
    if (perm[i] == i) v = i;
  if (v != 0) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++)
      if (v != i) cout << i << ' ' << v << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (perm[perm[i]] == i) v = i;
  if (v == 0) return cout << "NO" << endl, 0;
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      int cnt = 0;
      int u = i;
      while (!mark[u]) {
        mark[u] = true;
        turn[perm[u]] = !turn[u];
        u = perm[u];
        cnt++;
      }
      if (cnt % 2 == 1) return cout << "NO" << endl, 0;
    }
  cout << "YES" << endl;
  cout << v << ' ' << perm[v] << endl;
  for (int i = 1; i <= n; i++)
    if (i != v and i != perm[v])
      cout << i << ' ' << (turn[i] ? v : perm[v]) << '\n';
  return 0;
}
