#include <bits/stdc++.h>
using namespace std;
int p[200000];
int root = -1;
bool v[200000];
int ans;
int l[200000];
void dfs(int x) {
  if (p[x] == x && x == root) return;
  if (v[p[x]]) {
    if (l[p[x]] != l[x]) return;
    ans++;
    if (root == -1) {
      assert(p[x] != x);
      root = p[x] = x;
    } else {
      p[x] = root;
    }
  } else {
    v[p[x]] = 1;
    l[p[x]] = l[x];
    dfs(p[x]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
    if (p[i] == i) root = i;
  }
  for (int i = 0; i < n; i++) {
    if (!v[i] && i != root) {
      v[i] = 1;
      l[i] = i;
      dfs(i);
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) {
    printf("%d ", p[i] + 1);
  }
  printf("\n");
}
