#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15;
const double pi = acos(-1.0);
const int inf = 1 << 30;
const long long Mod = 1000000007;
const int N = 2e5 + 5;
int par[N];
int p[N];
int a[N];
int find(int cur) { return par[cur] == cur ? cur : find(par[cur]); }
bool merge(int u, int v) {
  u = find(u);
  v = find(v);
  par[u] = v;
  return u == v;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    a[i] = p[i];
    par[i] = i;
  }
  int root = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      root = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (merge(i, p[i])) {
      p[i] = i;
      if (!root) {
        root = i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      p[i] = root;
    }
  }
  int change = 0;
  for (int i = 1; i <= n; i++) {
    change += a[i] != p[i];
  }
  cout << change << '\n';
  for (int i = 1; i <= n; i++) {
    cout << p[i] << ' ';
  }
  cout << '\n';
  return 0;
}
