#include <bits/stdc++.h>
using namespace std;
int A[100005] = {0}, visit[100005] = {0};
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == A[i]) {
      cout << "YES\n";
      for (int j = 1; j <= n; j++) {
        if (j != i) {
          cout << j << " " << i << "\n";
        }
      }
      return;
    }
  }
  vector<pair<int, int> > gg;
  int k = -1;
  int a, b;
  for (int i = 1; i <= n; i++) {
    if (visit[i] == 0) {
      vector<int> lol;
      visit[i] = 1;
      while (1) {
        lol.push_back(i);
        i = A[i];
        if (visit[i] == 1) {
          break;
        }
        visit[i] = 1;
      }
      if (lol.size() == 2) {
        k = i;
        a = lol[0];
        b = lol[1];
        gg.push_back({a, b});
        break;
      }
    }
  }
  if (k == -1) {
    cout << "NO\n";
    return;
  }
  for (int i = 1; i <= n; i++) {
    visit[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (visit[i] == 0) {
      vector<int> lol;
      visit[i] = 1;
      while (1) {
        lol.push_back(i);
        i = A[i];
        if (visit[i] == 1) {
          break;
        }
        visit[i] = 1;
      }
      if (lol.size() % 2 == 1) {
        cout << "NO\n";
        return;
      }
      if (i == k) {
        continue;
      }
      for (int j = 0; j < lol.size(); j++) {
        if (j % 2 == 0) {
          gg.push_back({a, lol[j]});
        } else {
          gg.push_back({b, lol[j]});
        }
      }
    }
  }
  cout << "YES\n";
  for (int i = 0; i < n - 1; i++) {
    cout << gg[i].first << " " << gg[i].second << "\n";
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
