#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 100;
bool used[MN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < n; ++i) {
    if (v[i] == i + 1) {
      cout << "YES\n";
      for (int j = 0; j < n; ++j) {
        if (i != j) {
          cout << i + 1 << ' ' << j + 1 << '\n';
        }
      }
      return 0;
    }
  }
  vector<vector<int> > c;
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      int pos = v[i] - 1;
      c.push_back(vector<int>());
      while (pos != i) {
        c.back().push_back(pos);
        used[pos] = 1;
        pos = v[pos] - 1;
      }
      used[pos] = 1;
      c.back().push_back(pos);
    }
  }
  int mi = 1e9;
  int ei = 0;
  for (int i = 0; i < c.size(); ++i) {
    mi = min((int)c[i].size(), mi);
    if (c[i].size() % 2 != 0) {
      ei = 1;
    }
  }
  if (mi != 2 || ei) {
    cout << "NO\n";
    return 0;
  }
  memset(used, 0, sizeof used);
  int a = 0;
  int b = 0;
  cout << "YES\n";
  for (int i = 0; i < c.size(); ++i) {
    if (c[i].size() == 2) {
      used[i] = 1;
      cout << c[i][0] + 1 << ' ' << c[i][1] + 1 << '\n';
      a = c[i][0];
      b = c[i][1];
      break;
    }
  }
  for (int i = 0; i < c.size(); ++i) {
    if (used[i]) continue;
    for (int j = 0; j < c[i].size(); ++j) {
      if (j % 2 == 0) {
        cout << a + 1 << ' ' << c[i][j] + 1 << '\n';
      } else {
        cout << b + 1 << ' ' << c[i][j] + 1 << '\n';
      }
    }
  }
}
