#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 34;
const int maxlog = 20;
const int mod = 1e9 + 7;
const int sq = 720;
int par[maxn], mark[maxn];
vector<pair<int, int> > roots;
int main() {
  int n, ans = 0;
  cin >> n;
  int tof = 0;
  for (int i = 1; i <= n; i++) cin >> par[i];
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (mark[i]) continue;
    k++;
    int v = i, u;
    while (true) {
      mark[v] = k;
      u = par[v];
      if (mark[u] && mark[u] != mark[v]) break;
      if (mark[u] == mark[v]) {
        if (u == v)
          roots.push_back(make_pair(0, v));
        else
          roots.push_back(make_pair(1, v));
        break;
      }
      v = u;
    }
  }
  sort(roots.begin(), roots.end());
  if (roots[0].first == 1) {
    ans++;
    par[roots[0].second] = roots[0].second;
  }
  for (int i = 1; i < roots.size(); i++) {
    int v = roots[i].second;
    par[v] = roots[0].second;
    ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << par[i] << " ";
  return 0;
}
