#include <bits/stdc++.h>
using namespace std;
int v[200005], c[200005], f[200005], n, root, gs;
inline int dfs(int x) {
  if (c[x]) return c[x];
  if (v[x]) return c[x] = x;
  v[x] = 1;
  return c[x] = dfs(f[x]);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> f[i];
  for (int i = 1; i <= n; i++) dfs(i);
  for (int i = 1; i <= n; i++)
    if (c[i] == i && f[i] == i) root = i;
  if (!root) {
    for (int i = 1; i <= n; i++) {
      if (c[i] != i) continue;
      gs++;
      f[i] = i;
      root = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++)
    if (c[i] == i) {
      gs++;
      f[i] = root;
    }
  gs--;
  cout << gs << endl;
  for (int i = 1; i <= n; i++) cout << f[i] << " ";
  cout << endl;
  return 0;
}
