#include <bits/stdc++.h>
using namespace std;
int counter = 0;
int find_root(int x, int arr[], int brr[]) {
  brr[x] = 2;
  while (brr[arr[x]] != 2) {
    x = arr[x];
    brr[x] = 2;
  }
  arr[x] = x;
  return x;
}
void parent(int x, int root, int arr[], int brr[]) {
  if (brr[x] != 2) {
    if (brr[x] != 1) {
      brr[x] = 1;
      parent(arr[x], root, arr, brr);
    } else {
      arr[x] = root;
      counter++;
    }
  }
  brr[x] = 2;
}
int main() {
  int i, j, k, arr[200005], brr[200005] = {0}, root = 0;
  int n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (i = 1; i <= n; i++) {
    if (i == arr[i]) {
      root = i;
      brr[root] = 2;
      break;
    }
  }
  if (root == 0) {
    root = find_root(1, arr, brr);
    counter++;
  }
  i = 1;
  while (i <= n) {
    if (brr[i] != 2) {
      parent(i, root, arr, brr);
    }
    i++;
  }
  cout << counter << endl;
  for (i = 1; i <= n; i++) cout << arr[i] << " ";
  return 0;
}
