#include <bits/stdc++.h>
using namespace std;
int n, a[100050], cnt, vis[100050];
vector<int> P[100050];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      ++cnt;
      for (int j = i, k = 0; !vis[j]; j = a[j])
        vis[j] = ++k, P[cnt].push_back(j);
    }
  for (int i = 1; i <= cnt; i++)
    if ((int)P[i].size() == 1) {
      puts("YES");
      for (int j = 1; j <= n; j++)
        if (j != P[i][0]) printf("%d %d\n", j, P[i][0]);
      return 0;
    }
  for (int i = 1; i <= cnt; i++)
    if ((int)P[i].size() % 2 == 1) return puts("NO"), 0;
  for (int i = 1; i <= cnt; i++)
    if ((int)P[i].size() == 2) {
      puts("YES");
      printf("%d %d\n", P[i][0], P[i][1]);
      for (int j = 1; j <= n; j++)
        if (j != P[i][0] && j != P[i][1])
          printf("%d %d\n", j, P[i][vis[j] & 1]);
      return 0;
    }
  return puts("NO"), 0;
}
