#include <bits/stdc++.h>
using namespace std;
int a[200200], p[200200], n, ans, root = -1;
int Find(int x) {
  while (p[x] != x && x != -1) x = p[x];
  return x;
}
void Union(int x, int y) {
  int xRoot = Find(x);
  if (xRoot == y) {
    ans++;
    p[y] = root;
    a[y] = root;
  } else {
    p[y] = xRoot;
  }
}
int main() {
  int i, j;
  cin >> n;
  for (i = 0; i < n; i++) p[i] = i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    if (a[i] == i) {
      if (root == -1)
        root = a[i];
      else {
        a[i] = root;
        ans++;
      }
    } else
      Union(a[i], i);
  }
  if (root == -1) {
    for (i = 0; i < n; i++)
      if (a[i] == -1) {
        root = i;
        break;
      }
  }
  for (i = 0; i < n; i++)
    if (a[i] == -1) a[i] = root;
  cout << ans << endl;
  for (i = 0; i < n; i++) cout << a[i] + 1 << " ";
  return 0;
}
