#include <bits/stdc++.h>
using namespace std;
long long id[200005], a[200005];
long long root(long long x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, c = -1;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    id[i] = i;
    if (a[i] == i) c = i;
  }
  long long chang = 0;
  for (long long i = 1; i <= n; i++) {
    if (c == i) continue;
    if (root(i) == root(a[i])) {
      if (c == -1) c = i;
      a[i] = c, chang++;
    } else
      id[root(i)] = id[root(a[i])];
  }
  cout << chang << "\n";
  for (long long i = 1; i <= n; i++) cout << a[i] << " ";
}
