#include <bits/stdc++.h>
using namespace std;
long long vis[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  std::vector<long long> p(n + 1);
  for (long long int i = 1; i < n + 1; i++) {
    cin >> p[i];
    if (p[i] == i) {
      cout << "YES\n";
      for (long long int j = 1; j < n + 1; j++) {
        if (j != i) cout << i << " " << j << '\n';
      }
      exit(0);
    }
  }
  long long vl = 0;
  set<long long> check[100005];
  for (long long int i = 1; i < n + 1; i++) {
    if (p[p[i]] == i) {
      vl = i;
      break;
    }
  }
  if (!vl) {
    cout << "NO";
    exit(0);
  }
  std::vector<pair<long long int, long long int> > res;
  res.push_back({vl, p[vl]});
  vis[vl] = 1, vis[p[vl]] = 1;
  check[vl].insert(p[vl]);
  check[p[vl]].insert(vl);
  for (long long int i = 1; i < n + 1; i++) {
    if (vis[i] == 1) continue;
    res.push_back({vl, i});
    vis[vl] = 1, vis[i] = 1;
    check[vl].insert(i);
    check[i].insert(vl);
    long long s = i, e = vl;
    while (1) {
      if (vis[p[s]]) break;
      res.push_back({p[s], p[e]});
      s = p[s], e = p[e];
      vis[s] = 1, vis[e] = 1;
      check[s].insert(e);
      check[e].insert(s);
    }
    s = p[s], e = p[e];
    if (check[s].find(e) == check[s].end()) {
      cout << "NO";
      exit(0);
    }
  }
  cout << "YES\n";
  for (auto i : res) {
    cout << i.first << " " << i.second << '\n';
  }
}
