#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f7f7f7f;
const int MAXN = 200005;
const double eps = 1e-10;
int fa[MAXN], a[MAXN];
int findfa(int x) {
  if (x == fa[x]) return x;
  return fa[x] = findfa(fa[x]);
}
int main() {
  int n, i, id, ans, id1;
  while (scanf("%d", &n) != EOF) {
    id = -1;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] == i) id = i;
    }
    ans = 0;
    for (i = 1; i <= n; i++) fa[i] = i;
    for (i = 1; i <= n; i++) {
      int tx = findfa(i);
      int ty = findfa(a[i]);
      if (tx == ty) {
        ans++;
        id1 = i;
      } else {
        fa[tx] = ty;
      }
    }
    if (ans == 0 || (ans == 1 && id != -1)) {
      puts("0");
      for (i = 1; i <= n; i++) {
        printf("%d", a[i]);
        if (i != n)
          printf(" ");
        else
          puts("");
      }
      continue;
    }
    if (id == -1) {
      id = id1;
      a[id] = id;
      ans++;
    }
    for (i = 1; i <= n; i++) fa[i] = i;
    for (i = 1; i <= n; i++) {
      if (id == i) continue;
      int tx = findfa(i);
      int ty = findfa(a[i]);
      if (tx != ty) {
        fa[tx] = ty;
      } else {
        a[i] = id;
      }
    }
    printf("%d\n", ans - 1);
    for (i = 1; i <= n; i++) {
      printf("%d", a[i]);
      if (i != n)
        printf(" ");
      else
        puts("");
    }
  }
  return 0;
}
