#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100100];
vector<int> adj[100100];
int cyc = 0;
bool vis[100100];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int ind1 = -1, ind2 = -1;
  bool is_odd = false;
  ;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int curr = i;
    while (!vis[curr]) {
      adj[cyc].push_back(curr);
      vis[curr] = true;
      curr = arr[curr];
    }
    if (adj[cyc].size() == 2) {
      ind2 = cyc;
    }
    if (adj[cyc].size() == 1) {
      ind1 = cyc;
    }
    if (adj[cyc].size() % 2) is_odd = true;
    cyc++;
  }
  if (ind1 == -1 && ind2 == -1) {
    cout << "NO" << endl;
    return 0;
  }
  if (ind1 == -1 && is_odd) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  if (ind1 != -1) {
    int _a = adj[ind1][0];
    for (int i = 0; i < cyc; i++) {
      if (i == ind1) continue;
      for (int j = 0; j < adj[i].size(); j++) {
        int ch = adj[i][j];
        cout << _a << " " << ch << endl;
      }
    }
  } else {
    int _a = adj[ind2][0], _b = adj[ind2][1];
    cout << _a << " " << _b << endl;
    for (int i = 0; i < cyc; i++) {
      if (i == ind2) continue;
      for (int j = 0; j < adj[i].size(); j++) {
        int ch = adj[i][j];
        if (j % 2)
          cout << _a << " " << ch << endl;
        else
          cout << _b << " " << ch << endl;
      }
    }
  }
}
