#include <bits/stdc++.h>
using namespace std;
int pa[400005];
int find(int x) { return !pa[x] ? x : pa[x] = find(pa[x]); }
bool uni(int x, int y) {
  int i = find(x), j = find(y);
  if (i == j)
    return false;
  else {
    pa[i] = j;
  }
  return true;
}
int a[400005];
bool b[400005];
int main() {
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  memset(pa, 0, sizeof(pa));
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int root = 0;
  int cnt = 0;
  int cir = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == i) {
      if (!root)
        root = i;
      else
        b[i] = true, cnt++;
    } else {
      if (!uni(i, a[i])) {
        cir = i;
        b[i] = true, cnt++;
      }
    }
  }
  cout << cnt << endl;
  if (!root && cir) root = cir;
  for (int i = 1; i <= n; ++i) {
    if (b[i])
      cout << root << " ";
    else
      cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
