#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
vector<int> heads, circs;
int par[200005], color[200005];
void DFS(int s) {
  color[s] = 1;
  if (color[par[s]] == 0)
    DFS(par[s]);
  else if (color[par[s]] == 1) {
    if (par[s] == s)
      heads.push_back(s);
    else
      circs.push_back(s);
  }
  color[s] = 2;
}
int main() {
  int n, i, chng, s;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &par[i]);
    par[i]--;
    color[i] = 0;
  }
  for (i = 0; i < n; i++)
    if (color[i] == 0) DFS(i);
  chng = 0;
  s = 0;
  if (heads.size() == 0) {
    par[circs[0]] = circs[0];
    heads.push_back(circs[0]);
    chng = s = 1;
  }
  for (i = 1; i < heads.size(); i++) {
    par[heads[i]] = heads[0];
    chng++;
  }
  for (i = s; i < circs.size(); i++) {
    par[circs[i]] = heads[0];
    chng++;
  }
  printf("%d\n", chng);
  for (i = 0; i < n - 1; i++) printf("%d ", par[i] + 1);
  printf("%d\n", par[i] + 1);
  return 0;
}
