#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
bool ans = 1;
int n, d[N], p[N];
void dfs(int v) {
  int u = p[v];
  if (d[u] != 0 && (d[u] & 1) == (d[v] & 1)) ans = 0;
  if (d[u] == 0) {
    d[u] = d[v] + 1;
    dfs(u);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  int c1 = -1, c2 = -1;
  for (int i = 0; i < n; i++) {
    if (p[i] == i) c1 = i;
    if (p[p[i]] == i) c2 = i;
  }
  if (c1 != -1) {
    cout << "YES\n";
    for (int i = 0; i < n; i++)
      if (i != c1) cout << i + 1 << " " << c1 + 1 << "\n";
    return 0;
  }
  c1 = p[c2];
  if (c2 == -1) ans = 0;
  if (c2 != -1) {
    for (int i = 0; i < n; i++)
      if (d[i] == 0) {
        d[i] = 1;
        dfs(i);
      }
  }
  if (ans == 0) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  cout << c1 + 1 << " " << c2 + 1 << "\n";
  for (int i = 0; i < n; i++)
    if (i != c1 && i != c2) {
      if (d[i] & 1)
        cout << i + 1 << " " << c1 + 1 << "\n";
      else
        cout << i + 1 << " " << c2 + 1 << "\n";
    }
}
