#include <bits/stdc++.h>
using namespace std;
int n, f[200009], G = -1, ct, visit[200009], cnt;
void dfs(int x) {
  cnt++;
  while (!visit[f[x]]) {
    visit[x] = cnt;
    x = f[x];
  }
  if (visit[f[x]] == cnt) {
    if (G == -1) G = x;
    if (f[x] != G) f[x] = G, ct++;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> f[i];
  for (int i = 1; i <= n; i++) {
    if (f[i] == i) {
      G = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!visit[i]) dfs(i);
  cout << ct << endl;
  for (int i = 1; i <= n; i++) cout << f[i] << " ";
  return 0;
}
