#include <bits/stdc++.h>
using namespace std;
int p[200005];
int res[10][200005];
bool visit[200005 + 10];
int cnt[10];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  int index1 = -1, index2 = -1;
  for (int i = 0; i < n; i++) {
    if (p[i] == i) index1 = i;
    if (p[p[i]] == i) index2 = i;
  }
  if (index1 != -1) {
    puts("YES");
    for (int i = 0; i < n; i++)
      if (index1 != i) printf("%d %d\n", index1 + 1, i + 1);
  } else if (index2 != -1) {
    memset(visit, 0, sizeof visit);
    visit[index2] = 1;
    visit[p[index2]] = 1;
    int step = 1;
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (!visit[i]) {
        res[0][cnt[0]++] = i;
        visit[i] = 1;
        int curr = p[i];
        step = 1;
        while (curr != i) {
          res[step][cnt[step]++] = curr;
          visit[curr] = 1;
          curr = p[curr];
          step ^= 1;
        }
        if (step == 1) {
          flag = false;
          break;
        }
      }
    }
    if (!flag) {
      puts("NO");
      return 0;
    }
    puts("YES");
    printf("%d %d\n", index2 + 1, p[index2] + 1);
    for (int i = 0; i < cnt[0]; i++)
      printf("%d %d\n", index2 + 1, res[0][i] + 1);
    for (int i = 0; i < cnt[1]; i++)
      printf("%d %d\n", p[index2] + 1, res[1][i] + 1);
  } else
    puts("NO");
  return 0;
}
