#include <bits/stdc++.h>
using namespace std;
struct node {
  int next, to;
} a[400001];
int st[200001], vis[200001], fa[200001], last, cnt = 0, ans = 0, huan;
int roo[200001], roo2[200001];
void add(int x, int y) {
  a[++cnt].to = y;
  a[cnt].next = st[x];
  st[x] = cnt;
}
void dfs(int x, int last) {
  int i;
  if (vis[x]) {
    if (huan == 0) {
      huan = 1;
      roo[++roo[0]] = x;
      roo2[roo[0]] = 1;
    }
    return;
  }
  vis[x] = 1;
  for (i = st[x]; i; i = a[i].next)
    if (a[i].to != last) dfs(a[i].to, x);
}
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &fa[i]);
    if (fa[i] == i) continue;
    add(fa[i], i);
    add(i, fa[i]);
  }
  for (i = 1; i <= n; i++) {
    huan = 0;
    if (vis[i] == 0) {
      dfs(i, 0);
      if (huan == 0) {
        for (j = i; fa[j] != j; j = fa[j])
          ;
        roo[++roo[0]] = j;
      }
    }
  }
  for (i = 1; i <= roo[0]; i++)
    if (roo2[i] == 0) break;
  if (i <= roo[0]) {
    ans = roo[0] - 1;
    for (j = 1; j <= roo[0]; j++) fa[roo[j]] = roo[i];
  } else {
    ans = roo[0];
    for (j = 1; j <= roo[0]; j++) fa[roo[j]] = roo[1];
  }
  printf("%d\n", ans);
  for (i = 1; i <= n; i++) printf("%d ", fa[i]);
}
