#include <bits/stdc++.h>
using namespace std;
int perm[100010];
bool used[100010];
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < (int)(N); i++) {
    scanf("%d", perm + i);
    perm[i]--;
  }
  fill(used, used + N, false);
  bool cnt1 = false, cnt2 = false;
  int cy1;
  pair<int, int> cy2;
  for (int i = 0; i < (int)(N); i++) {
    if (!used[i]) {
      int cnt = 0, next = i;
      while (!used[next]) {
        used[next] = true;
        next = perm[next];
        cnt++;
      }
      if (cnt == 1) {
        cnt1 = true;
        cy1 = i;
      }
      if (cnt == 2) {
        cnt2 = true;
        cy2 = make_pair(i, perm[i]);
      }
    }
  }
  if (cnt1) {
    printf("YES\n");
    used[cy1] = true;
    for (int i = 0; i < (int)(N); i++) {
      if (i != cy1) {
        printf("%d %d\n", cy1 + 1, i + 1);
      }
    }
  } else if (cnt2) {
    vector<pair<int, int> > ans;
    used[cy2.first] = used[cy2.second] = true;
    ans.push_back(pair<int, int>(cy2.first + 1, cy2.second + 1));
    fill(used, used + N, 0);
    for (int i = 0; i < (int)(N); i++) {
      if (i != cy2.first && i != cy2.second && !used[i]) {
        int cnt = 0, next = i;
        while (!used[next]) {
          ans.push_back(pair<int, int>(
              next + 1, (cnt % 2 == 0 ? cy2.first : cy2.second) + 1));
          used[next] = true;
          next = perm[next];
          cnt++;
        }
        if (cnt % 2) {
          printf("NO\n");
          return 0;
        }
      }
    }
    printf("YES\n");
    for (pair<int, int> p : ans) {
      printf("%d %d\n", p.first, p.second);
    }
  } else {
    printf("NO\n");
  }
  return 0;
}
