#include <bits/stdc++.h>
using namespace std;
int a[123456];
int n;
int main() {
  cin >> n;
  int b = 0, c = 0, d = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) b = i;
    if (i == a[a[i]]) c = i;
  }
  if (b != 0) {
    puts("YES");
    for (int i = 1; i <= n; i++) {
      if (i != b) {
        printf("%d %d\n", i, b);
      }
    }
  } else if (c != 0) {
    bool vis[123456];
    memset(vis, false, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      int t = 0, j = i;
      j = i;
      while (!vis[j]) {
        vis[j] = true;
        j = a[j];
        t++;
      }
      if (t & 1) {
        puts("NO");
        return 0;
      }
    }
    memset(vis, false, sizeof(vis));
    puts("YES");
    printf("%d %d\n", c, a[c]);
    vis[c] = vis[a[c]] = true;
    for (int i = 1; i <= n; i++) {
      int t = 1, j;
      if (!vis[i]) {
        j = i;
        while (!vis[j]) {
          if (t)
            printf("%d %d\n", j, c);
          else
            printf("%d %d\n", j, a[c]);
          t ^= 1;
          vis[j] = true;
          j = a[j];
        }
      }
    }
  } else
    puts("NO");
  return 0;
}
