#include <bits/stdc++.h>
int pre[200000 + 10], a[200000 + 10];
int n;
int Find(int x) {
  if (x == pre[x]) return x;
  return pre[x] = Find(pre[x]);
}
void join(int x, int y) {
  int fx = pre[x], fy = pre[y];
  if (fx != fy) pre[fx] = fy;
}
int main() {
  scanf("%d", &n);
  int root = -1, i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre[i] = i;
    if (i == a[i]) root = i;
  }
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (i == a[i] && i != root) {
      cnt++;
      a[i] = root;
      join(i, a[i]);
    } else if (a[i] != i && Find(i) != Find(a[i]))
      join(i, a[i]);
    else if (a[i] != i && Find(i) == Find(a[i])) {
      cnt++;
      if (root == -1) root = i;
      a[i] = root;
      join(i, a[i]);
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
