#include <bits/stdc++.h>
using namespace std;
int n;
int p[200010];
int np[200010];
int nT[200010];
bool v[200010];
set<int> s;
int visit(int x, int o) {
  if (p[x] == x) {
    v[x] = 1;
    return np[x] = x;
  }
  nT[x] = o;
  v[x] = 1;
  int px = p[x];
  if (p[px] == px) return np[x] = px;
  if (v[px] == 0)
    return np[x] = visit(p[x], o);
  else {
    if (nT[px] == o)
      return np[x] = x;
    else
      return np[x] = np[px];
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  memset(v, 0, sizeof(v));
  int order = 0;
  for (int i = 1; i <= n; i++) {
    if (!v[i]) {
      order++;
      visit(i, order);
    }
  }
  for (int i = 1; i <= n; i++) {
    s.insert(np[i]);
  }
  int rs = 0;
  set<int>::iterator it;
  int root = -1;
  for (it = s.begin(); it != s.end(); it++) {
    if (p[*it] == *it) {
      root = *it;
      break;
    }
  }
  if (root == -1) {
    root = *(s.begin());
    p[root] = root;
    rs++;
  }
  for (it = s.begin(); it != s.end(); it++) {
    if (*it != root) {
      p[*it] = root;
      rs++;
    }
  }
  cout << rs << endl;
  for (int i = 1; i <= n; i++) {
    if (i != 1) cout << " ";
    cout << p[i];
  }
  cout << endl;
  return 0;
}
