#include <bits/stdc++.h>
using namespace std;
int a[200005], f[200005];
int getf(int k) { return k == f[k] ? k : f[k] = getf(f[k]); }
int main() {
  int n, t, cnt = 0, root = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) {
      root = i;
      cnt++;
    } else if (getf(i) == getf(a[i])) {
      cnt++;
      a[i] = i;
    }
    f[getf(i)] = getf(a[i]);
  }
  if (!root) {
    for (int i = 1; i <= n; i++)
      if (f[i] == i) {
        root = i;
      }
    cnt++;
  }
  printf("%d\n", cnt - 1);
  for (int i = 1; i <= n; i++) {
    if (i != f[i])
      printf("%d ", a[i]);
    else
      printf("%d ", root);
  }
  return 0;
}
