#include <bits/stdc++.h>
using namespace std;
int a[200010], par[200010], b[200010];
void init(int n) {
  for (int i = 1; i <= n; i++) par[i] = i;
}
int Find(int x) {
  if (par[x] == x) return x;
  return par[x] = Find(par[x]);
}
bool unite(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (x == y) return false;
  par[x] = y;
  return true;
}
int main() {
  int n, i, root, now, ans, p;
  scanf("%d", &n);
  init(n);
  root = p = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    int fx = Find(i), fy = Find(a[i]);
    if (fx == fy) {
      b[p++] = i;
      if (a[i] == i) root = fx;
    }
    unite(fx, fy);
  }
  if (root == 0) {
    for (i = 1; i <= n; i++) {
      int fx = Find(i), fy = Find(a[i]);
      if (fx == fy) root = fx;
    }
  }
  int cnt = 0;
  for (i = 0; i < p; i++) {
    if (a[b[i]] != root) {
      a[b[i]] = root;
      cnt++;
    }
  }
  printf("%d\n", cnt);
  for (i = 1; i <= n; i++) printf("%d%c", a[i], i == n ? '\n' : ' ');
}
