#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int f[N], n, a[N], p[N], opt, b[N], rt = -1, ans;
bool d;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == i) rt = i;
    if (i == find(a[i]))
      b[++opt] = i;
    else
      f[i] = a[i];
  }
  if (rt == -1)
    rt = b[opt];
  else
    d = 1;
  for (int i = 1; i <= opt; i++) a[b[i]] = rt;
  printf("%d\n", opt - d);
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
