#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long b = -1;
  long long ans = -1;
  for (long long i = (0); i < (n); i++) cin >> a[i], a[i]--;
  for (long long i = (0); i < (n); i++)
    if (i == a[i]) a[i] = b, b = i, ans++;
  for (long long i = (0); i < (n); i++)
    if (a[i] == -1) a[i] = i, b = i;
  vector<long long> use(n, -1);
  for (long long i = (0); i < (n); i++)
    if (use[i] < 0 && i != b) {
      long long fl = 0, c = i;
      while (1) {
        use[c] = i;
        c = a[c];
        if (c == b) break;
        if (use[c] != i && use[c] >= 0) break;
        if (use[c] == i) {
          fl = 1;
          break;
        }
      }
      if (fl)
        if (b != -1) a[c] = b, ans++;
      if (fl)
        if (b < 0) b = c, a[c] = c, ans = 1;
    }
  cout << ans << '\n';
  for (long long i = (0); i < (n); i++) cout << (a[i] + 1) << ' ';
  return 0;
}
