#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
vector<int> P;
int find(int u) {
  if (P[u] < 0) return u;
  return P[u] = find(P[u]);
}
bool arejoined(int a, int b) { return find(a) == find(b); }
void join(int a, int b) {
  if (arejoined(a, b)) return;
  a = find(a);
  b = find(b);
  if (P[a] < P[b]) {
    P[b] = a;
  } else if (P[b] < P[a]) {
    P[a] = b;
  } else {
    P[b] = a;
    P[a]--;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> p(n, 0), vis(n, 0);
  vector<int> pre(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i]--;
    pre[p[i]] = i;
  }
  int i = 0, k = 0;
  for (i = 0; !vis[i]; i = p[i]) {
    k++;
    vis[i] = 1;
  }
  int has_single_center = -1;
  int double_center = -1;
  for (int j = 0; j < n; ++j) {
    if (p[j] == j) has_single_center = j;
    if (p[p[j]] == j) double_center = j;
  }
  if (has_single_center < 0 && double_center < 0) {
    cout << "NO" << endl;
  } else {
    if (has_single_center > -1) {
      cout << "YES" << endl;
      for (int j = 0; j < n; ++j)
        if (has_single_center != j)
          cout << has_single_center + 1 << " " << j + 1 << endl;
      ;
    } else {
      int u = double_center, v = p[double_center];
      vis.assign(n, 0);
      bool ok = true;
      vector<pair<int, int> > ans;
      ans.push_back(pair<int, int>(u, v));
      vis[u] = 1;
      vis[v] = 1;
      for (int z = 0; z < n && ok; ++z) {
        if (vis[z]) continue;
        vector<int> cycles;
        for (int j = z; !vis[j]; j = p[j]) {
          vis[j] = 1;
          cycles.push_back(p[j]);
        }
        if (cycles.size() % 2 == 1) ok = false;
        for (int j = 0; j < cycles.size(); ++j) {
          if (j & 1)
            ans.push_back(pair<int, int>(u, cycles[j]));
          else
            ans.push_back(pair<int, int>(v, cycles[j]));
        }
      }
      if (ok) {
        cout << "YES" << endl;
        for (int j = 0; j < ans.size(); ++j) {
          cout << ans[j].first + 1 << " " << ans[j].second + 1 << endl;
        }
      } else {
        cout << "NO" << endl;
      }
    }
  }
  return 0;
}
