#include <bits/stdc++.h>
using namespace std;
int p[200010];
int father[200010];
int getfather(int x) {
  if (father[x] == 0) {
    return x;
  }
  return father[x] == x ? x : father[x] = getfather(father[x]);
}
int main() {
  int n;
  int f1, f2;
  int i, j;
  int cnt = 0;
  int root = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    if (root == 0) {
      if (p[i] == i) {
        father[i] = i;
        p[i] = i;
        root = i;
        cnt--;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    f1 = i;
    f2 = getfather(p[i]);
    if (i == p[i]) {
      if (root == 0) {
        root = i;
        father[i] = i;
      } else {
        father[i] = root;
        p[i] = root;
        cnt++;
      }
    } else if (father[p[i]] == 0) {
      father[i] = p[i];
    } else if (f1 != f2) {
      father[i] = p[i];
    } else {
      if (root == 0) {
        father[i] = i;
        p[i] = i;
        root = i;
        cnt++;
      } else {
        father[i] = root;
        p[i] = root;
        cnt++;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    getfather(i);
  }
  printf("%d\n", cnt);
  for (i = 1; i <= n; i++) {
    printf("%d", p[i]);
    if (i == n) {
      printf("\n");
    } else {
      printf(" ");
    }
  }
  return 0;
}
