#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const int N = 2e5 + 5;
stack<int> s;
int p[N], par[N], SCC[N];
int enter[N], low[N], timer, scc;
void Tarjan(int cur) {
  s.emplace(cur);
  enter[cur] = low[cur] = ++timer;
  if (enter[par[cur]]) {
    if (!SCC[par[cur]]) {
      low[cur] = low[cur] < enter[par[cur]] ? low[cur] : enter[par[cur]];
    }
  } else {
    Tarjan(par[cur]);
    low[cur] = low[cur] < low[par[cur]] ? low[cur] : low[par[cur]];
  }
  if (enter[cur] == low[cur]) {
    scc++;
    int x, c = 0;
    do {
      x = s.top(), s.pop();
      SCC[x] = scc, c++;
    } while (x != cur);
    if (c > 1) par[cur] = cur;
  }
}
int main() {
  int root = 0, change = 0;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", par + i);
    p[i] = par[i];
    if (par[i] == i) root = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!enter[i]) Tarjan(i);
  }
  for (int i = 1; i <= n; i++) {
    if (par[i] == i && !root) root = i;
  }
  for (int i = 1; i <= n; i++) {
    if (par[i] == i) par[i] = root;
  }
  for (int i = 1; i <= n; i++) {
    if (par[i] != p[i]) change++;
  }
  printf("%d\n", change);
  for (int i = 1; i <= n; i++) {
    printf("%d ", par[i]);
  }
  puts("");
}
