#include <bits/stdc++.h>
using namespace std;
int fa[200005];
int find(int x) {
  if (x == fa[x])
    return x;
  else
    return fa[x] = find(fa[x]);
}
int main() {
  int i, j, k, m, n;
  int a[200005];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int flag = 0;
  int cnt = 0;
  int gen = -1;
  for (int i = 1; i <= n; i++)
    if (a[i] == i) {
      cnt++;
      gen = i;
    }
  for (int i = 1; i <= n; i++) {
    int xx = find(i);
    int yy = find(a[i]);
    if (a[i] == i) continue;
    if (xx == yy) {
      a[i] = i;
      cnt++;
    } else
      fa[xx] = yy;
  }
  if (gen == -1)
    for (int i = 1; i <= n; i++)
      if (a[i] == i) {
        gen = i;
        cnt++;
        break;
      }
  printf("%d\n", --cnt);
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) a[i] = gen;
    printf("%d ", a[i]);
  }
  return 0;
}
