#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int deg[200010] = {};
bool root[200010] = {};
int root_size = 0;
int visited[200010] = {};
vector<int> vec;
int ans = 0;
vector<int> roots;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
    deg[i]++;
    if (a[i] == i) {
      roots.push_back(i);
      root[i] = true;
      root_size++;
    } else {
      deg[a[i]]++;
    }
  }
  for (int i = 0; i < n; i++) {
    int now = i;
    if (visited[i]) continue;
    while (1) {
      if (visited[now]) {
        if (visited[now] == i + 1) {
          vec.push_back(now);
        }
        break;
      }
      visited[now] = i + 1;
      if (now == a[now]) {
        break;
      }
      now = a[now];
    }
  }
  if (root_size == 0) {
    ans++;
    a[vec[0]] = vec[0];
    for (int i = 1; i < vec.size(); i++) {
      ans++;
      a[vec[i]] = vec[0];
    }
  } else {
    for (int i = 1; i < roots.size(); i++) {
      ans++;
      a[roots[i]] = roots[0];
    }
    for (int i = 0; i < vec.size(); i++) {
      ans++;
      a[vec[i]] = roots[0];
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) printf(i < n - 1 ? "%d " : "%d\n", a[i] + 1);
  return 0;
}
