#include <bits/stdc++.h>
using namespace std;
int dup[200100], p[200100];
void ini(int n) {
  for (int i = 1; i <= n; i++) dup[i] = i;
}
int findpar(int x) {
  while (x != dup[x]) {
    dup[x] = dup[dup[x]];
    x = dup[x];
  }
  return x;
}
bool merge(int a, int b) {
  int para = findpar(a);
  int parb = findpar(b);
  if (para == parb) return true;
  dup[parb] = para;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, res = -1, root = -1, i;
  cin >> n;
  ini(n);
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    if (i == p[i]) root = i;
  }
  if (root == -1) {
    res = 0;
  }
  for (i = 1; i <= n; i++) {
    if (merge(i, p[i])) {
      if (root == -1) root = i;
      ++res;
      p[i] = root;
    }
  }
  cout << res << "\n";
  for (i = 1; i <= n; i++) cout << p[i] << " ";
  cout << "\n";
  return 0;
}
