#include <bits/stdc++.h>
using namespace std;
int p[100010], par[100010], size[100010];
int find(int x) {
  if (x == par[x]) return x;
  return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  par[x] = y;
  size[y] += size[x];
}
vector<int> cycle[100010];
void find_cycle(int st) {
  cycle[st].push_back(st);
  int cur = p[st];
  while (cur != st) {
    cycle[st].push_back(cur);
    cur = p[cur];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
    par[i] = i;
    size[i] = 1;
  }
  for (int i = 1; i <= n; i++) unite(i, p[i]);
  int self_cycle = -1, two_node_cycle = -1;
  bool odd_cycle = false;
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      if (size[i] & 1) {
        if (size[i] == 1)
          self_cycle = i;
        else
          odd_cycle = true;
      } else {
        if (size[i] == 2) two_node_cycle = i;
      }
      find_cycle(i);
    }
  }
  if (self_cycle != -1) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (i != self_cycle) printf("%d %d\n", self_cycle, i);
  } else if (two_node_cycle != -1 && !odd_cycle) {
    puts("YES");
    for (int i = 1; i <= n; i++) {
      if (find(i) == i && i != two_node_cycle) {
        for (int j = 0; j < (int)cycle[i].size(); j++) {
          int x = cycle[i][j];
          if (!(j & 1)) {
            printf("%d %d\n", cycle[two_node_cycle][0], x);
          } else {
            printf("%d %d\n", cycle[two_node_cycle][1], x);
          }
        }
      }
    }
    printf("%d %d\n", cycle[two_node_cycle][0], cycle[two_node_cycle][1]);
  } else {
    puts("NO");
  }
  return 0;
}
