#include <bits/stdc++.h>
int n, i, s, l, t, A[200004], F[200004];
void Find(int x) {
  F[x] = ++l;
  while (F[A[x]] == 0) x = A[x], F[x] = l;
  if (F[A[x]] == l) {
    if (t == 0) t = x;
    if (A[x] != t) A[x] = t, s++;
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (i = 1; i <= n; i++)
    if (i == A[i]) t = i;
  for (i = 1; i <= n; i++)
    if (F[i] == 0) Find(i);
  printf("%d\n", s);
  for (i = 1; i <= n; i++) printf("%d ", A[i]);
}
