#include <bits/stdc++.h>
using namespace std;
int p[223456];
vector<int> vec;
int dsu[223456];
int find(int u) {
  if (dsu[u] < 0) return u;
  dsu[u] = find(dsu[u]);
  return dsu[u];
}
int merge(int u, int v) {
  if (dsu[u] < dsu[v]) {
    dsu[v] = u;
  } else if (dsu[v] < dsu[u]) {
    dsu[u] = v;
  } else {
    dsu[u] = v;
    dsu[v]--;
  }
  return 0;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int root = -1;
  int i, a, b;
  for (i = 0; i < n + 22; i++) {
    dsu[i] = -1;
  }
  for (i = 1; i < n + 1; i++) {
    cin >> p[i];
    if (p[i] == i) {
      if (root == -1) {
        root = i;
      } else {
        vec.push_back(i);
      }
    } else {
      a = find(i);
      b = find(p[i]);
      if (a != b) {
        merge(a, b);
      } else {
        vec.push_back(i);
      }
    }
  }
  cout << vec.size() << endl;
  if (root == -1) {
    root = vec[0];
  }
  for (i = 0; i < vec.size(); i++) {
    p[vec[i]] = root;
  }
  for (i = 1; i < n + 1; i++) {
    cout << p[i] << " ";
  }
  return 0;
}
