#include <bits/stdc++.h>
using namespace std;
template <template <typename...> class TT, typename... Args>
ostream& operator<<(ostream& cout, TT<Args...> const& s) {
  cout << "[";
  for (auto x : s) cout << " " << x;
  return cout << " ]";
}
const long long MX = 5e5 + 1;
const long long LL_MAX = 1e18 + 3;
const long long MOD = 1e9 + 7;
pair<long long, long long> DISP[8] = {{1, 0}, {0, 1},   {-1, 0}, {0, -1},
                                      {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
bool compare(vector<long long> a, vector<long long> b) {
  return (long long)a.size() < (long long)b.size();
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n), visited(n, 0);
  for (long long i = 0; i < n; i++) cin >> a[i], a[i]--;
  vector<vector<long long> > cycles;
  bool flg = false;
  for (long long i = 0; i < n; i++) {
    if (visited[i]) continue;
    vector<long long> c;
    long long nxt = i;
    while (!visited[nxt]) {
      c.push_back(nxt);
      visited[nxt] = true;
      nxt = a[nxt];
    }
    cycles.push_back(c);
    if ((long long)c.size() % 2) flg = true;
  }
  sort(cycles.begin(), cycles.end(), compare);
  vector<long long> C = cycles.front();
  if ((long long)C.size() > 2 || ((long long)C.size() == 2 && flg)) {
    cout << "NO" << '\n';
    return;
  }
  cout << "YES" << '\n';
  if ((long long)C.size() == 1) {
    C[0]++;
    for (long long i = 1; i <= n; i++)
      if (C[0] != i) cout << C[0] << " " << i << '\n';
  } else {
    cout << C[0] + 1 << " " << C[1] + 1 << '\n';
    long long ctr = 1;
    for (long long i = 1; i < (long long)cycles.size(); i++)
      for (auto y : cycles[i]) cout << C[ctr++ % 2] + 1 << " " << y + 1 << '\n';
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
