#include <bits/stdc++.h>
using namespace std;
int a[200004], vis[200003];
queue<int> q;
int cmp, root;
void dfs(int u) {
  vis[u] = cmp;
  if (!vis[a[u]])
    dfs(a[u]);
  else if (vis[a[u]] == cmp)
    q.push(u);
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == a[i]) root = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ++cmp;
      dfs(i);
    }
  }
  int cnt = 0;
  if (!root) {
    root = q.front();
    a[root] = root;
    cnt++;
    q.pop();
  }
  while (!q.empty()) {
    if (q.front() != root) {
      a[q.front()] = root;
      cnt++;
    }
    q.pop();
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
