#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int f[maxn], a[maxn], ans[maxn], vis[maxn], cir[maxn];
int n, i, j, root, cnt, x;
int find(int o) {
  if (o == f[o]) return o;
  return f[o] = find(f[o]);
}
int get(int o) {
  while (!cir[o]) {
    cir[o] = 1;
    o = a[o];
  }
  return o;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) f[i] = i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) root = i;
    find(i);
    find(a[i]);
    if (f[i] != f[a[i]]) f[f[i]] = f[a[i]];
  }
  if (root) {
    find(root);
    vis[f[root]] = 1;
    for (i = 1; i <= n; i++) {
      find(i);
      if (vis[f[i]]) continue;
      vis[f[i]] = 1;
      x = get(i);
      cnt++;
      a[x] = root;
    }
  } else {
    find(1);
    vis[f[1]] = 1;
    x = get(1);
    root = x;
    a[x] = x;
    cnt = 1;
    for (i = 1; i <= n; i++) {
      find(i);
      if (vis[f[i]]) continue;
      vis[f[i]] = 1;
      x = get(i);
      cnt++;
      a[x] = root;
    }
  }
  printf("%d\n", cnt);
  for (i = 1; i <= n; i++) printf("%d%c", a[i], i < n ? ' ' : '\n');
  return 0;
}
