#include <bits/stdc++.h>
using namespace std;
void MAIN();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  MAIN();
  return 0;
}
const int N = 1e6 + 1, mod = 1e9 + 7;
int rs, done[N], a[N], n, root;
void MAIN() {
  cin >> n;
  for (int i = 1; i <= (n); ++i) cin >> a[i];
  for (int i = 1; i <= (n); ++i)
    if (a[i] == i) root = i;
  for (int i = 1; i <= (n); ++i) {
    int j;
    for (j = i; !done[j]; j = a[j]) done[j] = i;
    if (done[j] != i) continue;
    if (j == root) continue;
    if (!root) root = j;
    ++rs;
    a[j] = root;
  }
  cout << rs << endl;
  for (int i = 1; i <= (n); ++i) cout << a[i] << " ";
}
