#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(9);
  cerr.setf(ios::fixed);
  cerr.precision(3);
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  return 0;
}
const int MAXN = 100100;
int n;
int p[MAXN];
bool used[MAXN];
void solve(int test_number) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 0; i < n; i++) {
    if (i == p[i]) {
      cout << "YES"
           << "\n";
      for (int j = 0; j < n; j++) {
        if (j != i) {
          cout << i + 1 << ' ' << j + 1 << '\n';
        }
      }
      return;
    }
  }
  int p1 = -1, p2 = -1;
  for (int i = 0; i < n; i++) {
    vector<int> c;
    if (used[i]) continue;
    int cur = i;
    while (!used[cur]) {
      used[cur] = true;
      c.push_back(cur);
      cur = p[cur];
    }
    if (c.size() % 2 != 0) {
      cout << "NO" << endl;
      return;
    }
    if (c.size() == 2) {
      p1 = c[0], p2 = c[1];
    }
  }
  if (p1 == -1) {
    cout << "NO" << endl;
    return;
  }
  memset(used, 0, sizeof(used));
  cout << "YES" << endl;
  cout << p1 + 1 << ' ' << p2 + 1 << endl;
  used[p1] = used[p2] = true;
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    vector<int> c;
    int cur = i;
    int flag = 0;
    while (!used[cur]) {
      if (flag)
        cout << p1 + 1 << ' ' << cur + 1 << "\n";
      else
        cout << p2 + 1 << ' ' << cur + 1 << "\n";
      flag = 1 - flag;
      used[cur] = true;
      c.push_back(cur);
      cur = p[cur];
    }
  }
}
