#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, ans, root;
int f[N], fa[N];
inline int read() {
  int a = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = a * 10 + c - '0';
    c = getchar();
  }
  return a * f;
}
int find(int i) { return f[i] == i ? i : f[i] = find(f[i]); }
int main() {
  n = read();
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= n; i++) {
    fa[i] = read();
    if (fa[i] == i) root = i;
  }
  for (int i = 1; i <= n; i++) {
    if (i != root) {
      int p = find(i), q = find(fa[i]);
      if (p == q) {
        ans++;
        if (!root) root = i;
        fa[i] = root;
      } else
        f[p] = q;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d%c", fa[i], i == n ? '\n' : ' ');
  return 0;
}
