#include <bits/stdc++.h>
using namespace std;
int n, cycle1, cycle2, cur, H[(int)(2e5 + 10)], p[(int)(2e5 + 10)];
bool cift;
vector<int> ans[2];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) cycle1 = i;
    if (p[p[i]] == i) cycle2 = i;
  }
  if (!cycle1 and !cycle2) return puts("NO"), 0;
  if (cycle1) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (i != cycle1) printf("%d %d\n", cycle1, i);
    return 0;
  }
  H[cycle2] = H[p[cycle2]] = 1;
  for (int i = 1; i <= n; i++)
    if (!H[i]) {
      H[i] = 1;
      cur = i;
      cift = true;
      while (true) {
        H[cur] = 1;
        if (cift)
          ans[0].push_back(cur);
        else
          ans[1].push_back(cur);
        cur = p[cur];
        cift = !cift;
        if (cur == i) break;
      }
      if (!cift) return puts("NO"), 0;
    }
  puts("YES");
  cout << cycle2 << ' ' << p[cycle2] << '\n';
  for (__typeof(ans[0].begin()) it = ans[0].begin(); it != ans[0].end(); it++)
    printf("%d %d\n", cycle2, *it);
  for (__typeof(ans[1].begin()) it = ans[1].begin(); it != ans[1].end(); it++)
    printf("%d %d\n", p[cycle2], *it);
}
