#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
T sqr(const T &x) {
  return x * x;
}
template <typename T>
T my_abs(const T &x) {
  return x < 0 ? -x : x;
}
const int INF = (int)1e9;
const long long LINF = (long long)4e18;
const long long INF64 = (long long)LINF;
const long long INFLL = (long long)LINF;
const long double EPS = 1e-8;
const long double ME = 1e-5;
const long long MOD = (int)1e9 + 7;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const int N = (int)1e5 + 10;
const int M = (int)5e1 + 10;
const int SQN = 400;
const int LOGN = 24;
int p[N];
bool used[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    cin >> p[i];
    p[i]--;
  }
  vector<vector<int> > cycles;
  for (int i = 0; i < int(n); ++i) {
    if (!used[i]) {
      vector<int> cur;
      int j = i;
      while (!used[j]) {
        used[j] = true;
        cur.push_back(j);
        j = p[j];
      }
      cycles.push_back(cur);
    }
  }
  int v = -1;
  int v1 = -1, v2 = -1, idx;
  bool nc = false;
  for (int i = 0; i < int(int(cycles.size())); ++i) {
    if (int(cycles[i].size()) == 1) {
      v = cycles[i][0];
      break;
    }
    if (int(cycles[i].size()) == 2) {
      v1 = cycles[i][0];
      v2 = cycles[i][1];
      idx = i;
    }
    if (int(cycles[i].size()) % 2 == 1) {
      nc = true;
    }
  }
  if (v == -1) {
    if (v1 != -1 && nc == false) {
      cout << "YES" << endl;
      vector<pair<int, int> > ans;
      ans.push_back(make_pair(v1, v2));
      for (int i = 0; i < int(int(cycles.size())); ++i) {
        if (i != idx) {
          for (int j = 0; j < int(int(cycles[i].size()) / 2); ++j) {
            ans.push_back(make_pair(cycles[i][2 * j], v1));
            ans.push_back(make_pair(cycles[i][2 * j + 1], v2));
          }
        }
      }
      for (int i = 0; i < int(int(ans.size())); ++i) {
        cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
      }
    } else {
      cout << "NO" << endl;
    }
  } else {
    cout << "YES" << endl;
    for (int i = 0; i < int(n); ++i) {
      if (i != v) {
        cout << v + 1 << ' ' << i + 1 << endl;
      }
    }
  }
}
int main() {
  srand((unsigned int)time(NULL));
  cout << setprecision(10) << fixed;
  solve();
  return 0;
}
