#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
map<long long int, vector<long long int>> adj;
deque<long long int> d;
deque<long long int> q;
map<long long int, bool> mark;
long long int a[MAXN];
vector<pair<int, int>> ans;
void addEdge(long long int u, long long int v) { adj[u].push_back(v); }
void BFS(long long int u) {
  mark[u] = true;
  d.push_back(u);
  while (!d.empty()) {
    long long int x = d.front();
    q.push_back(x);
    d.pop_front();
    for (int i = 0; i < adj[x].size(); i++) {
      long long int y = adj[x][i];
      if (!mark[y]) {
        d.push_back(y);
        mark[y] = true;
      }
    }
  }
}
void DFS(long long int u) {
  mark[u] = true;
  d.push_back(u);
  while (!d.empty()) {
    long long int x = d.back();
    q.push_back(x);
    cout << x << ' ';
    d.pop_back();
    for (int i = 0; i < adj[x].size(); i++) {
      long long int y = adj[x][i];
      if (!mark[y]) {
        d.push_back(y);
        mark[y] = true;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  bool fl = false;
  int k = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == a[i]) {
      k = i;
      fl = true;
    }
  }
  if (fl) {
    cout << "YES" << endl;
    for (int j = 1; j <= n; j++) {
      if (j != k) cout << a[k] << ' ' << a[j] << endl;
    }
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i == a[a[i]]) {
      mark[i] = true;
      mark[a[i]] = true;
      int x = i, y = a[i];
      bool b = true;
      ans.push_back({x, y});
      bool c = true;
      for (int j = 1; j <= n; j++) {
        if (mark[a[j]]) continue;
        int cnt = 0;
        int t = a[j];
        do {
          if (b)
            ans.push_back({x, t});
          else
            ans.push_back({y, t});
          b = !b;
          mark[t] = true;
          t = a[t];
          cnt++;
        } while (a[j] != t);
        if (cnt % 2 != 0) {
          c = false;
          break;
        }
      }
      if (!c) break;
      cout << "YES" << endl;
      for (int j = 0; j < ans.size(); j++)
        cout << ans[j].first << ' ' << ans[j].second << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
