#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int p[maxn], num;
bool used[maxn];
vector<int> G, H;
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int flag = 0;
    memset(used, 0, sizeof(used));
    G.clear(), H.clear();
    for (int i = 1; i <= n; ++i) {
      scanf("%d", p + i);
      if (p[i] == i) flag = i;
    }
    if (flag) {
      puts("YES");
      for (int i = 1; i <= n; ++i) {
        if (i == flag) continue;
        printf("%d %d\n", flag, i);
      }
    } else {
      int x = 0, y = 0;
      for (int i = 1; i <= n; ++i) {
        if (!used[i]) {
          used[i] = true;
          num = 1;
          int t = p[i];
          while (t != i) {
            if (num & 1)
              G.push_back(t);
            else
              H.push_back(t);
            used[t] = true;
            t = p[t];
            num++;
          }
          if (num & 1)
            G.push_back(t);
          else
            H.push_back(t);
          if (num & 1) {
            flag = 1;
            break;
          } else if (num == 2) {
            x = i;
            y = p[i];
          }
        }
      }
      if (flag || (x == 0 && y == 0))
        puts("NO");
      else {
        memset(used, 0, sizeof(used));
        puts("YES");
        printf("%d %d\n", x, y);
        used[x] = used[y] = true;
        for (int i = 0; i < G.size(); ++i) {
          int u = G[i];
          if (!used[u]) {
            used[u] = true;
            printf("%d %d\n", x, u);
          }
        }
        for (int i = 0; i < H.size(); ++i) {
          int u = H[i];
          if (!used[u]) {
            used[u] = true;
            printf("%d %d\n", y, u);
          }
        }
      }
    }
  }
}
