#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int p[N];
int root;
vector<pair<int, int> > ans;
void print_ans() {
  printf("YES\n");
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i].first && ans[i].second)
      printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
bool vis[N];
int cycle_len;
void DFS(int v, int connect) {
  ans.push_back(make_pair(v, connect));
  vis[v] = true;
  cycle_len++;
  if (!vis[p[v]]) DFS(p[v], p[connect]);
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (i = 1; i <= n; i++) {
    if (i == p[i]) root = i;
  }
  if (root) {
    for (i = 1; i <= n; i++) {
      if (i != root) ans.push_back(make_pair(root, i));
    }
    print_ans();
    return 0;
  }
  root = 0;
  for (i = 1; i <= n; i++) {
    if (p[p[i]] == i) {
      root = i;
    }
  }
  if (!root) {
    printf("NO\n");
    return 0;
  }
  vis[root] = vis[p[root]] = true;
  ans.push_back(make_pair(root, p[root]));
  for (i = 1; i <= n; i++) {
    if (!vis[i]) {
      cycle_len = 0;
      DFS(i, root);
      if (cycle_len & 1) {
        printf("NO\n");
        return 0;
      }
    }
  }
  print_ans();
  return 0;
}
