#include <bits/stdc++.h>
using namespace std;
vector<int> G[100000 + 2];
bool vis[100000 + 2];
void dfs(int u, int &cnt, vector<int> &v) {
  vis[u] = 1;
  v.push_back(u);
  cnt++;
  for (int i = 0; i < (int)G[u].size(); i++) {
    if (!vis[G[u][i]]) dfs(G[u][i], cnt, v);
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    G[i].push_back(x);
  }
  vector<int> v;
  bool enc = 0, enc2 = 0, imp = 0;
  int nodo = -1, n1 = -1, n2 = -1;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    if (vis[i]) continue;
    dfs(i, cnt, v);
    if (cnt % 2 == 1) imp = 1;
    if (cnt == 1 && !enc) {
      nodo = i;
      enc = 1;
    }
    if ((cnt == 2) && !enc2) {
      n1 = v[(int)v.size() - 1];
      n2 = v[(int)v.size() - 2];
      enc2 = 1;
    }
  }
  if (enc) {
    puts("YES");
    for (int i = 0; i < (int)v.size(); i++)
      if (v[i] != nodo) printf("%d %d\n", nodo + 1, v[i] + 1);
  } else {
    if (enc2) {
      if (imp)
        puts("NO");
      else {
        puts("YES");
        for (int i = 0; i < (int)v.size(); i++) {
          if (v[i] == n1 || v[i] == n2) continue;
          if (i & 1)
            printf("%d %d\n", n1 + 1, v[i] + 1);
          else
            printf("%d %d\n", n2 + 1, v[i] + 1);
        }
        printf("%d %d\n", n1 + 1, n2 + 1);
      }
    } else {
      puts("NO");
    }
  }
}
