#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a[200001], flag[200001], cnt(0), root(0), j, res(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == a[i]) root = i;
  }
  fill(flag + 1, flag + 200001, 0);
  for (i = 1; i <= n; i++) {
    if (flag[i] == 0) {
      cnt++;
      j = i;
      while (flag[j] == 0) {
        flag[j] = cnt;
        j = a[j];
      }
      if (flag[j] == cnt) {
        if (root == 0) {
          root = j;
          a[j] = j;
          res++;
        }
        if (root != j) {
          a[j] = root;
          res++;
        }
      }
    }
  }
  cout << res << '\n';
  for (i = 1; i <= n; i++) cout << a[i] << " ";
}
