#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> p(100005);
vector<vector<long long int>> cycles(100005);
vector<pair<long long int, long long int>> edges;
vector<long long int> visited(100005);
long long powmod(long long x, long long y, long long m) {
  long long res = 1LL;
  while (y) {
    if (y & 1) res = (res * x) % m;
    x = (x * x) % m;
    y /= 2;
  }
  return res;
}
void dfs(long long int u, long long int noc) {
  if (visited[u]) return;
  visited[u] = 1;
  cycles[noc].push_back(u);
  dfs(p[u], noc);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> p[i];
  long long int pos = 0;
  for (long long int i = 1; i <= n; i++) {
    if (p[i] == i) pos = i;
  }
  if (pos) {
    cout << "YES\n";
    for (long long int i = 1; i <= n; i++) {
      if (pos != i) cout << i << " " << pos << "\n";
    }
    return 0;
  }
  long long int noc = 0;
  long long int sz2 = 0;
  for (long long int i = 1; i <= n; i++) {
    if (!visited[i]) {
      noc++;
      dfs(i, noc);
      if (cycles[noc].size() % 2) {
        cout << "NO\n";
        return 0;
      }
      if (cycles[noc].size() == 2) sz2 = noc;
    }
  }
  if (sz2 == 0) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  edges.push_back(make_pair(cycles[sz2][0], cycles[sz2][1]));
  for (long long int i = 1; i <= noc; i++) {
    if (i != sz2) {
      for (long long int j = 0; j < cycles[i].size(); j++) {
        edges.push_back(make_pair(cycles[sz2][j % 2], cycles[i][j]));
      }
    }
  }
  for (long long int i = 0; i < edges.size(); i++)
    cout << edges[i].first << " " << edges[i].second << "\n";
  return 0;
}
