#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200020;
int F[MAXN], a[MAXN];
int find(int x) { return F[x] == x ? x : F[x] = find(F[x]); }
int n, root;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    F[i] = i;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == i) {
      root = i;
      F[i] = i;
    } else if (find(a[i]) == i) {
      F[i] = i;
    } else
      F[i] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (F[i] == i) {
      if (root == 0) {
        root = i;
        a[i] = i;
        cnt++;
      } else if (i != root) {
        a[i] = root;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) {
    printf(i == 1 ? "%d" : " %d", a[i]);
  }
  cout << endl;
  return 0;
}
