#include <bits/stdc++.h>
using namespace std;
int visi[200002];
int v[200002];
int main() {
  int n;
  cin >> n;
  int cc = -1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i]--;
    if (v[i] == i) cc = i;
  }
  int t = 0;
  int brojac = 0;
  for (int i = 0; i < n; i++) {
    if (!visi[i]) {
      t++;
      int x = i;
      while (!visi[x]) {
        visi[x] = t;
        x = v[x];
      }
      if (visi[x] == t) {
        if (cc == -1) {
          cc = x;
          v[x] = x;
          brojac++;
        }
        if (cc != x) {
          v[x] = cc;
          brojac++;
        }
      }
    }
  }
  cout << brojac << endl;
  for (int i = 0; i < n; i++) {
    cout << v[i] + 1;
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
