#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1 << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
void CI(long long &_x) { scanf("%d", &_x); }
void CO(long long &_x) { cout << _x; }
template <typename T>
void getarray(T a[], long long n) {
  for (long long i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void prLLIarray(T a[], long long n) {
  for (long long i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const long long INF = 0x7f7f7f7f;
long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dr4[4] = {0, 0, 1, -1};
long long dc4[4] = {-1, 1, 0, 0};
long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int ar[100005];
vector<int> V;
int main() {
  V.push_back(0);
  int n;
  cin >> n;
  int temp;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    V.push_back(temp);
  }
  int find1 = -1, find2 = -1;
  for (int i = 1; i <= n; i++) {
    if (V[i] == i) {
      find1 = i;
      break;
    }
    if (V[V[i]] == i) {
      find2 = i;
    }
  }
  if (find1 == -1 && find2 == -1) {
    puts("NO");
    return 0;
  }
  if (find1 != -1) {
    puts("YES");
    for (long long i = 1; i <= n; i++)
      if (i != find1) {
        cout << i << " " << find1 << "\n";
      }
    return 0;
  }
  int rem = 0;
  vector<pair<int, int> > res;
  if (find2 != -1) {
    int x = find2;
    int y = V[x];
    ar[x] = 1, ar[y] = 1;
    res.push_back(make_pair(x, y));
    int alter = 0;
    for (int i = 1; i <= n; i++) {
      int temp = i;
      while (ar[temp] == 0) {
        alter ^= 1;
        ar[temp] = 1;
        res.push_back(make_pair(x, temp));
        x = V[x];
        temp = V[temp];
      }
      if (alter) {
        puts("NO");
        return 0;
      }
    }
    puts("YES");
    for (int i = 0; i < res.size(); i++)
      cout << res[i].first << " " << res[i].second << "\n";
    return 0;
  }
  puts("NO");
}
