#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int a[100005], vis[100005];
pair<int, int> t;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  bool flag = false;
  int num = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) {
      flag = true;
      num = i;
    }
  }
  if (flag) {
    printf("YES\n");
    for (int i = 1; i <= n; i++) {
      if (i == num) continue;
      printf("%d %d\n", i, num);
    }
    return 0;
  }
  for (int i = 0; i < 100005; i++) v[i].clear();
  memset(vis, 0, sizeof(vis));
  if (n % 2 == 1) {
    printf("NO\n");
    return 0;
  }
  int cnt = 0;
  bool found = false;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    if (i == a[a[i]] && !found) {
      found = true;
      t = pair<int, int>(i, a[i]);
      vis[i] = true;
      vis[a[i]] = true;
      continue;
    }
    int tmp = i;
    vis[tmp] = true;
    v[cnt].push_back(tmp);
    while (a[tmp] != i) {
      v[cnt].push_back(a[tmp]);
      vis[a[tmp]] = true;
      tmp = a[tmp];
    }
    cnt++;
  }
  if (!found) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < cnt; i++) {
    if (v[i].size() % 2 == 1) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (j % 2 == 1)
        printf("%d %d\n", t.first, v[i][j]);
      else
        printf("%d %d\n", t.second, v[i][j]);
    }
  }
  printf("%d %d\n", t.first, t.second);
  return 0;
}
