#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 100;
int p[N], a = -1;
bool mark[N];
void dfs(int u, bool k = false) {
  mark[u] = true;
  if (k == false)
    cout << u << ' ' << a << '\n';
  else
    cout << u << ' ' << p[a] << '\n';
  if (mark[p[u]] == false) dfs(p[u], !k);
}
int t(int u) {
  mark[u] = true;
  if (mark[p[u]] == false)
    return t(p[u]) + 1;
  else
    return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  int only = -1;
  for (int i = 1; i <= n; i++)
    if (i == p[i]) {
      only = i;
      break;
    }
  if (only != -1) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      if (i == only) continue;
      cout << only << ' ' << i << '\n';
    }
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (p[p[i]] == i) {
      a = i;
      break;
    }
  if (a == -1) {
    cout << "NO\n";
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (mark[i] == false && t(i) % 2 == 1) {
      cout << "NO\n";
      return 0;
    }
  for (int i = 0; i < N; i++) mark[i] = false;
  cout << "YES\n";
  cout << a << ' ' << p[a] << '\n';
  mark[a] = true;
  mark[p[a]] = true;
  for (int i = 1; i <= n; i++) {
    if (mark[i] == false) dfs(i);
  }
  return 0;
}
