#include <bits/stdc++.h>
using namespace std;
int n, a[200042], par[200042], rootInd = -1;
bool able[200042];
int getP(int x) { return par[x] == 0 ? x : par[x] = getP(par[x]); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == a[i]) {
      rootInd = i;
      continue;
    }
    int p1 = getP(i), p2 = getP(a[i]);
    if (p1 != p2) {
      par[p1] = p2;
      able[i] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (able[i]) {
      continue;
    }
    if (i == a[i]) {
      if (rootInd == i) {
        continue;
      } else {
        a[i] = rootInd;
        ans++;
      }
    } else {
      if (rootInd == -1) {
        rootInd = i;
        a[i] = i;
        ans++;
      } else {
        a[i] = rootInd;
        ans++;
      }
    }
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
  return 0;
}
