#include <bits/stdc++.h>
struct BCJ {
  int f[200005];
  void init(int n) {
    for (int i = (1); i <= (n); i++) f[i] = i;
  }
  int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
  bool ask(int x, int y) { return find(x) == find(y); }
  void uset(int x, int y) { f[find(x)] = find(y); }
} bcj;
int N, X[200005];
int main() {
  scanf("%d", &N);
  bcj.init(N);
  for (int i = (1); i <= (N); i++) scanf("%d", &X[i]);
  int R = 0, a = 0;
  for (int i = (1); i <= (N); i++)
    if (i == X[i]) {
      R = i;
      break;
    }
  if (R) {
    for (int i = (1); i <= (N); i++)
      if (bcj.ask(X[i], i) && i != R)
        bcj.uset(i, R), X[i] = R, a++;
      else
        bcj.uset(i, X[i]);
  } else {
    for (int i = (1); i <= (N); i++)
      if (bcj.ask(X[i], i)) {
        if (R)
          bcj.uset(i, R), X[i] = R, a++;
        else
          R = i, X[R] = R, a++;
      } else
        bcj.uset(i, X[i]);
  }
  printf("%d\n", a);
  for (int i = (1); i <= (N); i++) printf("%d ", X[i]);
}
