#include <bits/stdc++.h>
using namespace std;
int N, f[200010], fa[200010];
int get(int x) { return (fa[x] != x ? fa[x] = get(fa[x]) : x); }
int main() {
  while (scanf("%d", &N) == 1) {
    for (int i = 1; i <= N; i++) scanf("%d", &f[i]);
    for (int i = 1; i <= N; i++) fa[i] = i;
    int root = 0, cnt = 0;
    for (int i = 1; i <= N; i++) {
      if (f[i] == i)
        root = i, cnt++;
      else {
        int x = get(i), y = get(f[i]);
        if (x == y) {
          f[i] = i, cnt++;
        } else
          fa[x] = y;
      }
    }
    if (root == 0) {
      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 (f[i] == i) f[i] = root;
      printf("%d%c", f[i], " \n"[i == N]);
    }
  }
  return 0;
}
