#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
const int inf = 1e9 + 10;
using namespace std;
int a[maxn], p[maxn];
int findx(int x) {
  if (p[x] < 0) return x;
  return p[x] = findx(p[x]);
}
bool qsc_merge(int u, int v) {
  u = findx(u), v = findx(v);
  if (u == v) return false;
  if (p[u] < p[v]) swap(u, v);
  p[v] += p[u];
  p[u] = v;
  return true;
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int rt = 0, ans = 0;
    for (int i = 1; i <= n; ++i) {
      p[i] = -1;
      scanf("%d", a + i);
      if ((a[i] == i) && (rt == 0)) rt = i;
    }
    for (int i = 1; i <= n; ++i) {
      if (i != rt) {
        if (!qsc_merge(i, a[i])) {
          ++ans;
          if (rt == 0) rt = i;
          a[i] = rt;
          qsc_merge(rt, i);
        }
      }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i) printf("%d%c", a[i], " \n"[i == n]);
  }
  return 0;
}
