#include <bits/stdc++.h>
using namespace std;
int a[100005];
int ix, n;
bool ck1() {
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) {
      ix = i;
      return true;
    }
  }
  return false;
}
void print1() {
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    if (i != ix) cout << ix << " " << i << endl;
  }
}
bool visit[100005];
int ckLen(int x, int ct) {
  if (visit[x]) return ct;
  visit[x] = true;
  ct++;
  return ckLen(a[x], ct);
}
bool isCyclic() {
  for (int i = 0; i <= n; i++) visit[i] = false;
  for (int i = 1; i <= n; i++) {
    if (!visit[i]) {
      if (ckLen(i, 0) % 2 != 0) return true;
    }
  }
  return false;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (ck1()) {
    print1();
    return 0;
  }
  if (isCyclic()) {
    cout << "NO\n";
    return 0;
  }
  bool fg = false;
  for (int i = 1; i <= n; i++) {
    if (a[a[i]] == i) {
      fg = true;
      ix = i;
    }
  }
  if (fg) {
    map<int, int> mp;
    cout << "YES\n";
    cout << ix << " " << a[ix] << endl;
    mp[ix] = 1;
    mp[a[ix]] = 1;
    for (int i = 1; i <= n; i++) {
      if (mp.find(i) == mp.end()) {
        int ct = 0;
        for (int j = i; mp.find(j) == mp.end(); j = a[j]) {
          if (ct % 2 == 0)
            cout << ix << " " << j << endl;
          else
            cout << a[ix] << " " << j << endl;
          ct++;
          mp[j] = 1;
        }
      }
    }
    return 0;
  }
  cout << "NO\n";
}
