#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
int p[100010];
int check[100010];
int c1, c2;
int n;
int ok = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      printf("YES\n");
      for (int j = 1; j <= n; j++) {
        if (j == i) continue;
        printf("%d %d\n", i, j);
      }
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i == p[p[i]]) {
      ok = 1;
      c1 = i;
      c2 = p[i];
      break;
    }
  }
  if (!ok) {
    printf("NO");
    return 0;
  }
  vector<int> tmp;
  for (int i = 1; i <= n; i++) {
    tmp.clear();
    if (i == c1 || i == c2) continue;
    int x = p[i];
    while (!check[x]) {
      check[x] = 1;
      tmp.push_back(x);
      x = p[x];
    }
    if (tmp.size() % 2) {
      printf("NO");
      return 0;
    }
    for (int i = 0; i < tmp.size(); i++) {
      if (i % 2) {
        ans.push_back(pair<int, int>(c1, tmp[i]));
      } else {
        ans.push_back(pair<int, int>(c2, tmp[i]));
      }
    }
  }
  ans.push_back(pair<int, int>(c1, c2));
  printf("YES\n");
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
}
