#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
int p[M], mk[M], root = -1, ans = 0;
void setroot(int u) {
  mk[u] = 1;
  if (!mk[p[u]])
    setroot(p[u]);
  else {
    ans = 1;
    p[u] = u;
    root = u;
  }
  mk[u] = 0;
}
void dfs(int v) {
  mk[v] = 1;
  if (!mk[p[v]])
    dfs(p[v]);
  else if (mk[p[v]] == 1 && v != root) {
    ans++;
    p[v] = root;
  }
  mk[v] = 2;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    --p[i];
    if (p[i] == i) root = i;
  }
  if (root < 0) setroot(0);
  for (int i = 0; i < n; i++)
    if (!mk[i]) dfs(i);
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << ++p[i] << " ";
  cout << endl;
  return 0;
}
