#include <bits/stdc++.h>
using namespace std;
vector<int> G[100000 + 5];
vector<vector<int> > bucket[100000 + 5];
vector<int> vec;
int vis[100000 + 5];
void dfs(int u, int p) {
  vis[u] = 1;
  vec.push_back(u + 1);
  for (auto v : G[u])
    if (!vis[v] && v != p) dfs(v, u);
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) G[i].clear();
    for (int i = 0; i < n + 1; i++) bucket[i].clear();
    for (int i = 0; i < n; i++) {
      int p;
      scanf("%d", &p);
      p--;
      G[i].push_back(p);
    }
    for (int i = 0; i < n; i++) vis[i] = 0;
    bool odd = 0;
    for (int i = 0; i < n; i++)
      if (!vis[i]) {
        vec.clear();
        dfs(i, -1);
        if (((int)(vec).size()) & 1) odd++;
        bucket[((int)(vec).size())].push_back(vec);
      }
    if (((int)(bucket[1]).size())) {
      puts("YES");
      vector<int> r = bucket[1].back();
      int root = r[0];
      bucket[1].pop_back();
      for (int L = 1; L <= n; ++L)
        for (auto arr : bucket[L])
          for (auto v : arr) printf("%d %d\n", root, v);
      continue;
    }
    if (((int)(bucket[2]).size()) && !odd) {
      puts("YES");
      printf("%d %d\n", bucket[2][0][0], bucket[2][0][1]);
      for (int i = 0; i < ((int)(bucket[2]).size()) - 1; i++) {
        printf("%d %d\n", bucket[2][i][0], bucket[2][i + 1][0]);
        printf("%d %d\n", bucket[2][i][1], bucket[2][i + 1][1]);
      }
      vector<int> r = bucket[2].back();
      for (int L = 4; L <= n; ++L)
        for (auto arr : bucket[L])
          for (int i = 0; i < ((int)(arr).size()); i++)
            printf("%d %d\n", r[i & 1], arr[i]);
      continue;
    }
    puts("NO");
  }
}
