#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
const int mod = 1e9 + 7;
const ll inf = 1e9;
const ll INF = 2e18;
const int N = 2e6 + 66;
int p[N], used[N];
void solve() {
  int n;
  cin >> n;
  if (n == 1) return void(cout << "YES");
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  vector<vector<int>> cycles;
  for (int i = 1; i <= n; ++i) {
    if (used[i]) continue;
    vector<int> now;
    int j = i;
    while (!used[j]) {
      used[j] = 1;
      now.push_back(j);
      j = p[j];
    }
    cycles.push_back(now);
  }
  sort(cycles.begin(), cycles.end(),
       [](vector<int> a, vector<int> b) { return a.size() < b.size(); });
  auto a = cycles[0];
  if ((int)a.size() > 2) return void(cout << "NO");
  if ((int)a.size() == 1) {
    cout << "YES\n";
    for (int i = 1; i < (int)cycles.size(); ++i) {
      auto b = cycles[i];
      for (int j = 0; j < (int)b.size(); ++j) {
        cout << a[0] << " " << b[j] << "\n";
      }
    }
    return;
  }
  bool ok = true;
  for (int i = 1; i < (int)cycles.size(); ++i) {
    ok &= cycles[i].size() % 2 == 0;
  }
  if (!ok) return void(cout << "NO");
  cout << "YES\n" << a[0] << " " << a[1] << "\n";
  for (int i = 1; i < (int)cycles.size(); ++i) {
    auto b = cycles[i];
    for (int j = 0; j < (int)b.size(); ++j) {
      cout << a[j & 1] << " " << b[j] << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int tt = 1;
  while (tt--) {
    solve();
    cout << "\n";
  }
}
