#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, num, num2;
int d[N], a[N], f[N];
vector<int> v;
void NO() {
  cout << "NO";
  exit(0);
}
void SOLVED(int X) {
  cout << "YES\n";
  int first;
  for (int i = 1; i <= n; i++)
    if (d[i] == X) first = i;
  for (int i = 1; i <= n; i++)
    if (first != i) cout << i << " " << first << "\n";
  exit(0);
}
void DFS(int first) {
  if (d[first] != -1) return;
  d[first] = v.size();
  f[v.size()] = first;
  num++;
  DFS(a[first]);
}
int FIND() {
  for (int i = 0; i <= (int)v.size() - 1; i++)
    if (v[i] == 2) return i;
  return -1;
}
void NOI(int X, int Y) {
  int first = f[X], second = f[Y];
  for (int ___ = 1; ___ <= max(v[X], v[Y]); ___++) {
    cout << first << " " << second << "\n";
    first = a[first], second = a[second];
  }
}
int main() {
  n = ({
    long long first = 0;
    int n = 0, c = getchar();
    for (; !isdigit(c); c = getchar()) n = c == '-';
    for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
    n ? -first : first;
  });
  memset(d, -1, sizeof(d));
  for (int i = 1; i <= n; i++)
    a[i] = ({
      long long first = 0;
      int n = 0, c = getchar();
      for (; !isdigit(c); c = getchar()) n = c == '-';
      for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
      n ? -first : first;
    });
  for (int i = 1; i <= n; i++)
    if (d[i] == -1) {
      num = 0;
      DFS(i);
      num2 += num % 2 == 0;
      v.push_back(num);
    }
  for (int i = 0; i <= (int)v.size() - 1; i++)
    if (v[i] == 1) SOLVED(i);
  if (num2 != v.size()) NO();
  int X = FIND();
  if (X == -1) NO();
  cout << "YES\n";
  for (int i = 0; i <= (int)v.size() - 1; i++)
    if (i != X) NOI(i, X);
  X = f[X];
  cout << X << " " << a[X] << "\n";
}
