#include <bits/stdc++.h>
using namespace std;
int n, p[210000], used[210000], used2[210000], root, ans, good_root = -1;
vector<int> l[210000];
vector<int> comp;
vector<int> roots;
void dfs(int v) {
  used[v] = 1;
  comp.push_back(v);
  int k = l[v].size();
  for (int i = 0; i < k; i++) {
    int v2 = l[v][i];
    if (!used[v2]) dfs(v2);
  }
  return;
}
void cycle_dfs(int v) {
  used2[v] = 1;
  while (used2[p[v]] == 0) {
    v = p[v];
    used2[v] = 1;
  }
  root = p[v];
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (i != p[i]) {
      l[i].push_back(p[i]);
      l[p[i]].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      comp.clear();
      dfs(i);
      root = -1;
      int k = comp.size();
      for (int j = 0; j < k; j++)
        if (p[comp[j]] == comp[j] || p[p[comp[j]]] == comp[j]) {
          root = comp[j];
          break;
        }
      if (root == -1) {
        cycle_dfs(i);
      }
      roots.push_back(root);
    }
  }
  int k = roots.size();
  for (int i = 0; i < k; i++) {
    if (p[roots[i]] == roots[i]) {
      good_root = roots[i];
      break;
    }
  }
  if (good_root == -1) {
    good_root = roots[0];
    p[roots[0]] = roots[0];
    ans++;
  }
  for (int i = 0; i < k; i++) {
    int rt = roots[i];
    if (rt != good_root) {
      p[rt] = good_root;
      ans++;
    }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << ' ';
  return 0;
}
