#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  int p[n + 1];
  for (int i = 1; i <= n; i++) {
    std::cin >> p[i];
  }
  int cycle1_start = -1, cycle2_start = -1;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) cycle1_start = i;
    if (p[p[i]] == i) cycle2_start = i;
  }
  if (cycle1_start != -1) {
    std::cout << "YES" << std::endl;
    for (int i = 1; i <= n; i++) {
      if (i != cycle1_start) std::cout << cycle1_start << " " << i << std::endl;
    }
    return 0;
  }
  if (cycle2_start != -1) {
    int cnt_even_odd[] = {0, 0};
    int div[2][n];
    int u[n + 1];
    std::memset(u, 0, sizeof(u));
    u[cycle2_start] = 1;
    u[p[cycle2_start]] = 1;
    for (int i = 1; i <= n; i++) {
      if (u[i]) continue;
      u[i] = 1;
      div[1][cnt_even_odd[1]++] = i;
      int rem = 0;
      int curI = p[i];
      while (curI != i) {
        u[curI] = 1;
        div[rem][cnt_even_odd[rem]++] = curI;
        rem ^= 1;
        curI = p[curI];
      }
      if (rem == 0) {
        std::cout << "NO" << std::endl;
        return 0;
      }
    }
    std::cout << "YES" << std::endl;
    std::cout << cycle2_start << " " << p[cycle2_start] << std::endl;
    for (int i = 0; i < cnt_even_odd[0]; i++)
      std::cout << cycle2_start << " " << div[0][i] << std::endl;
    for (int i = 0; i < cnt_even_odd[1]; i++)
      std::cout << p[cycle2_start] << " " << div[1][i] << std::endl;
    return 0;
  }
  std::cout << "NO" << std::endl;
  return 0;
}
