#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
const int INF = 0x3f3f3f3f;
int a[maxn], fa[maxn], b[maxn];
int vis[maxn], c[maxn], tot = 0;
int findfa(int x) { return fa[x] == x ? x : fa[x] = findfa(fa[x]); }
void uni(int x, int y) {
  int fax = findfa(x);
  int fay = findfa(y);
  if (fax != fay)
    fa[fax] = fay;
  else
    b[++tot] = x;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < maxn; i++) fa[i] = i;
  int p = 0;
  int root;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) {
      p++;
      if (p == 1)
        root = i;
      else
        b[++tot] = i;
    } else
      uni(i, a[i]);
  }
  int st = 1;
  if (p == 0) {
    a[b[1]] = b[1];
    root = b[1];
  }
  printf("%d\n", tot);
  for (int i = 1; i <= tot; i++) {
    if (b[i] == root) continue;
    if (findfa(root) == findfa(b[i])) continue;
    a[b[i]] = root;
  }
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
}
