#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int maxn = 100000 + 10;
int p[maxn];
pair<int, int> ans;
bool vis[maxn];
int num[maxn];
int main() {
  int n;
  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 (i != j) {
          printf("%d %d\n", i, j);
        }
      return 0;
    }
  memset(vis, false, sizeof(vis));
  memset(num, 0, sizeof(num));
  bool flag = false, one = false;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      int cnt = 0, x = i;
      while (!vis[x]) {
        vis[x] = true;
        cnt++;
        x = p[x];
      }
      if (cnt & 1)
        one = true;
      else if (cnt == 2 && !flag) {
        ans = make_pair(x, p[x]);
        flag = true;
      } else {
        num[x] = cnt;
      }
    }
  if (!flag || one) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  printf("%d %d\n", ans.first, ans.second);
  for (int i = 1; i <= n; i++)
    if (num[i]) {
      int val = num[i], x = i;
      while (val) {
        printf("%d %d\n", ans.first, x);
        printf("%d %d\n", ans.second, p[x]);
        x = p[p[x]];
        val -= 2;
      }
    }
  return 0;
}
