#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
bool mrk[MAXN], chn[MAXN];
int p[MAXN], ch[MAXN], n, ans = 0, root = -1, deg[MAXN];
queue<int> q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    deg[i]++;
    deg[p[i]]++;
    if (i == p[i]) root = i;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (p[u] == u) continue;
    mrk[u] = true;
    int viz = p[u];
    deg[viz]--;
    if (deg[viz] == 1) q.push(viz);
  }
  for (int i = 1; i <= n; i++) {
    if (mrk[i]) continue;
    int j = i;
    while (!mrk[j]) {
      mrk[j] = true;
      j = p[j];
    }
    if (j == root) continue;
    chn[j] = true;
    ans++;
  }
  if (root == -1) {
    for (int i = 1; i <= n; i++)
      if (chn[i]) {
        root = i;
        break;
      }
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    if (chn[i])
      cout << root << " ";
    else
      cout << p[i] << " ";
  }
}
