#include <bits/stdc++.h>
int root, p[1000000 + 3], dd[1000000 + 3], ans, n, j;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    if (p[i] == i) root = i;
  }
  for (int i = 1; i <= n; i++) {
    for (j = i; !dd[j]; j = p[j]) dd[j] = i;
    if (dd[j] != i) continue;
    if (j == root) continue;
    if (root == 0) root = j;
    p[j] = root;
    ans++;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", p[i]);
}
