#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
int sor[maxn], n;
int ff[maxn], cur;
int dfs(int v) {
  if (ff[v] == -1) {
    if (v == sor[v])
      cur = 0;
    else
      cur = 1;
    return ff[v] = v;
  }
  if (ff[v]) return -2;
  ff[v] = -1;
  return ff[v] = dfs(sor[v]);
}
int main() {
  int gfa = -1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &sor[i]);
    if (i == sor[i]) gfa = i;
  }
  int f, ans = -1;
  if (gfa == -1) {
    gfa = dfs(1);
    sor[gfa] = gfa;
    ans = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (ff[i]) continue;
    f = dfs(i);
    if (f == -2)
      continue;
    else {
      sor[f] = gfa;
      ans++;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d", sor[i]);
    if (i == n)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
