#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int n, fa[N], p[N], cnt, mk, la[N], size[N];
int getfa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getfa(fa[x]);
}
void merge(int x, int y) {
  int fx = getfa(x), fy = getfa(y);
  if (fx == fy) return;
  fa[fx] = fy;
  size[fy] += size[fx];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    size[i] = 1;
    if (p[i] == i) {
      if (!mk)
        mk = i;
      else
        p[i] = mk, cnt++;
    }
  }
  if (!mk) {
    for (int i = 1; i <= n; i++) merge(i, p[i]);
    int now = 0;
    for (int i = 1; i <= n; i++) {
      if (size[i] > now) {
        now = size[i];
        mk = i;
      }
    }
    for (int i = 1; i <= n; i++) fa[i] = i;
    p[mk] = mk;
    cnt++;
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) continue;
    if (getfa(i) == getfa(p[i])) p[i] = mk, cnt++;
    merge(i, p[i]);
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  cout << endl;
  return 0;
}
