#include <bits/stdc++.h>
using namespace std;
int a[100005], vis[100005];
vector<int> v[100005];
vector<pair<int, int> > ans;
int main() {
  int n, i, j, p, c, two, one, flag = 0;
  scanf("%d", &n);
  ;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ;
  }
  c = 0;
  for (i = 1; i <= n; i++) {
    p = i;
    while (!vis[p]) {
      ;
      v[c].push_back(p);
      vis[p] = 1;
      p = a[p];
    }
    c++;
  };
  one = -1;
  two = -1;
  for (i = 0; i < c; i++) {
    if (v[i].size() != 1 and v[i].size() != 2) {
      if (v[i].size() % 2 == 1) {
        flag = 1;
      }
    }
    if (v[i].size() == 1) {
      one = i;
    }
    if (v[i].size() == 2) {
      two = i;
    }
  }
  if (one == -1 && two == -1) {
    cout << "NO";
    return 0;
  }
  if (one > -1) {
    for (i = 1; i <= n; i++) {
      if (i == v[one][0]) {
      } else {
        ans.push_back(make_pair(v[one][0], i));
      }
    }
    cout << "YES\n";
    for (i = 0; i < ans.size(); i++) {
      cout << ans[i].first << " " << ans[i].second << "\n";
    }
    return 0;
  }
  if (flag == 1) {
    cout << "NO";
    return 0;
  }
  if (two > -1) {
    for (i = 0; i < c; i++) {
      if (i == two) {
        continue;
      } else {
        for (j = 0; j < v[i].size(); j += 2) {
          ans.push_back(make_pair(v[i][j], v[two][0]));
          ans.push_back(make_pair(v[i][j + 1], v[two][1]));
        }
      }
    }
    ans.push_back(make_pair(v[two][0], v[two][1]));
  }
  cout << "YES\n";
  for (i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
