#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
int fa[maxn], N, in[maxn], vis[maxn];
void tuopu(int x) {
  while (!in[x]) {
    vis[x] = 1;
    x = fa[x];
    in[x]--;
    if (vis[x]) break;
  }
}
int fcir(int x) {
  while (!vis[x]) {
    vis[x] = 2;
    x = fa[x];
  }
  return x;
}
int main() {
  int fir = -1, ans = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &fa[i]);
    if (i == fa[i]) {
      if (-1 != fir) {
        ans++;
        fa[i] = fir;
        in[fir]++;
      } else
        fir = fa[i];
    } else
      in[fa[i]]++;
  }
  for (int i = 1; i <= N; i++)
    if (!in[i] && !vis[i]) tuopu(i);
  if (-1 != fir) {
    for (int i = 1; i <= N; i++) {
      if (!vis[i]) {
        ans++;
        int x = fcir(i);
        fa[x] = fir;
      }
    }
  } else {
    for (int i = 1; i <= N; i++) {
      if (!vis[i]) {
        vis[i] = 2;
        int x = fa[i];
        while (!vis[x]) {
          vis[x] = 2;
          x = fa[x];
        }
        fir = i;
        fa[i] = i;
        ans++;
        break;
      }
    }
    for (int i = 1; i <= N; i++) {
      if (!vis[i]) {
        ans++;
        int x = fcir(i);
        fa[x] = fir;
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= N; i++) printf("%d ", fa[i]);
  return 0;
}
