#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200000 + 64;
int fa[MaxN], p[MaxN];
int cnt, root, s;
void FindSet(int x) {
  fa[x] = ++cnt;
  while (fa[p[x]] == 0) x = p[x], fa[x] = cnt;
  if (fa[p[x]] == cnt) {
    if (root == 0) root = x;
    if (p[x] != root) p[x] = root, s++;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n && !root; i++)
    if (i == p[i]) root = i;
  for (int i = 1; i <= n; i++)
    if (!fa[i]) FindSet(i);
  cout << s << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  return 0;
}
