#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 100 + 10;
int n, alone;
vector<vector<int> > v;
bool mark[maxN];
int p[maxN];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] == i) alone = i;
  }
  if (alone != 0) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++)
      if (i != alone) cout << i << " " << alone << endl;
  } else {
    int x[2];
    bool found = 0;
    for (int i = 1; i <= n; i++) {
      if (p[p[i]] == i) {
        mark[i] = mark[p[i]] = 1;
        x[0] = i;
        x[1] = p[i];
        found = 1;
        break;
      }
    }
    if (!found) {
      cout << "NO" << endl;
      return 0;
    }
    for (int i = 1; i <= n; i++) {
      if (!mark[i]) {
        vector<int> c;
        c.push_back(i);
        mark[i] = 1;
        int cnt = 1, now = i;
        while (p[now] != i) {
          cnt++;
          now = p[now];
          mark[now] = 1;
          c.push_back(now);
        }
        if (cnt % 2 == 1) {
          cout << "NO" << endl;
          return 0;
        }
        v.push_back(c);
      }
    }
    cout << "YES" << endl;
    cout << x[0] << " " << x[1] << endl;
    for (int j = 0; j < v.size(); j++)
      for (int k = 0; k < v[j].size(); k++)
        cout << x[k % 2] << " " << v[j][k] << endl;
  }
  return 0;
}
