#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], n, c[N], tot, b[N];
bool pd[N];
void dfs(int x) {
  pd[x] = false;
  if (pd[a[x]]) {
    c[a[x]] = c[x];
    dfs(a[x]);
  } else {
    if (c[a[x]] == c[x]) b[++tot] = x;
  }
}
int main() {
  memset(pd, true, sizeof(pd));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    if (pd[i]) {
      c[i] = i;
      dfs(i);
    }
  int r = 0;
  int ans = tot;
  for (int i = 1; i <= tot; i++)
    if (a[b[i]] == b[i]) r = b[i];
  if (r == 0)
    r = b[1];
  else
    ans--;
  for (int i = 1; i <= tot; i++)
    if (b[i] != r)
      a[b[i]] = r;
    else
      a[b[i]] = b[i];
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  printf("\n");
  return 0;
}
