#include <bits/stdc++.h>
using namespace std;
int n, a[100111];
int visited[100111];
void solve() {
  for (int i = (1), _b = (n); i <= _b; i++)
    if (a[i] == i) {
      cout << "YES\n";
      for (int j = (1), _b = (n); j <= _b; j++)
        if (j != i) cout << i << ' ' << j << '\n';
      return;
    }
  for (int t = (1), _b = (n); t <= _b; t++)
    if (a[a[t]] == t) {
      int u = t, v = a[t];
      memset(visited, 0, sizeof visited);
      visited[u] = visited[v] = 1;
      vector<pair<int, int> > res;
      res.push_back(make_pair(u, v));
      for (int i = (1), _b = (n); i <= _b; i++)
        if (!visited[i]) {
          int x = i;
          int cnt = 0;
          while (!visited[x]) {
            ++cnt;
            if (cnt & 1)
              res.push_back(make_pair(u, x));
            else
              res.push_back(make_pair(v, x));
            visited[x] = true;
            x = a[x];
          }
          if (cnt % 2 == 1) {
            cout << "NO\n";
            return;
          }
        }
      cout << "YES\n";
      for (auto p : res) cout << p.first << ' ' << p.second << '\n';
      return;
    }
  cout << "NO\n";
}
int main() {
  ios ::sync_with_stdio(false);
  while (cin >> n) {
    for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i];
    solve();
  }
}
