#include <bits/stdc++.h>
using namespace std;
void operator delete(void*) {}
const long long N = 100000 + 113;
const long long Mod = (long long)1e9 + 7;
const double eps = 1e-9;
long long n, p[N], One = -1, Other = -1;
bool used[N];
vector<pair<int, int>> ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] == i) {
      cout << "YES" << endl;
      for (int j = 1; j < i; j++) {
        cout << j << ' ' << i << endl;
      }
      for (int j = i + 1; j <= n; j++) {
        cout << j << ' ' << i << endl;
      }
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == p[p[i]]) {
      One = i;
      Other = p[i];
    }
  }
  if (One == -1) {
    cout << "NO";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i] || i == One || i == Other) {
      continue;
    }
    int v = i;
    int to = p[i];
    ans.push_back(make_pair(One, v));
    ans.push_back(make_pair(Other, to));
    used[v] = used[to] = 1;
    v = p[to];
    to = p[v];
    if (to == i) {
      cout << "NO";
      return 0;
    }
    while (v != i) {
      used[v] = used[to] = 1;
      ans.push_back(make_pair(One, v));
      ans.push_back(make_pair(Other, to));
      v = p[to];
      to = p[v];
      if (to == i) {
        cout << "NO";
        return 0;
      }
    }
  }
  ans.push_back(make_pair(One, Other));
  cout << "YES" << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
}
