#include <bits/stdc++.h>
const long long inf = std::numeric_limits<long long>::max();
using namespace std;
int a[100100];
vector<vector<int>> dor;
vector<pair<int, int>> ans;
bool seen[100100];
bool big(vector<int> w, vector<int> y) { return w.size() < y.size(); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    a[i] = x;
  }
  for (int i = 0; i < n; i++) {
    if (!seen[i]) {
      int j = i;
      vector<int> now;
      while (!seen[j]) {
        now.push_back(j);
        seen[j] = true;
        j = a[j];
      }
      dor.push_back(now);
    }
  }
  sort(dor.begin(), dor.end(), big);
  if (dor[0].size() == 1) {
    for (int i = 1; i < dor.size(); i++) {
      for (int j = 0; j < dor[i].size(); j++) {
        ans.push_back({dor[0][0], dor[i][j]});
      }
    }
  } else if (dor[0].size() == 2) {
    ans.push_back({dor[0][1], dor[0][0]});
    for (int i = 1; i < dor.size(); i++) {
      if (dor[i].size() % 2) {
        cout << "NO";
        return 0;
      }
      for (int j = 1; j < dor[i].size(); j++) {
        ans.push_back({dor[0][0], dor[i][j - 1]});
        ans.push_back({dor[0][1], dor[i][j++]});
      }
    }
  }
  if (ans.empty() && n != 1) {
    cout << "NO";
    return 0;
  }
  cout << "YES" << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
  }
  return 0;
}
