#include <bits/stdc++.h>
using namespace std;
int v[100005], a[100005];
vector<pair<int, int> > ans;
void dfs(int x, int y, int num) {
  if (v[y]) {
    if (num % 2) {
      cout << "NO";
      exit(0);
    }
    return;
  }
  v[x] = v[y] = 1;
  ans.push_back(make_pair(x, y));
  dfs(a[x], a[y], num + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  int i, j, k, l, n, m, f1 = 0, f2 = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i) f1 = i;
    if (i == a[a[i]]) f2 = i;
  }
  if (f1) {
    cout << "YES\n";
    for (i = 1; i <= n; i++)
      if (i != f1) cout << a[i] << " " << f1 << endl;
  } else if (f2) {
    v[f2] = v[a[f2]] = 1;
    ans.push_back(make_pair(f2, a[f2]));
    for (i = 1; i <= n; i++)
      if (!v[i]) dfs(f2, i, 0);
    cout << "YES\n";
    for (i = 0; i < ans.size(); i++)
      cout << ans[i].first << " " << ans[i].second << '\n';
  } else
    cout << "NO";
  return 0;
}
