#include <bits/stdc++.h>
const int mod = 1e9 + 7;
int mul(int x, int y) { return 1LL * x * y % mod; }
int qpow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = mul(res, x);
    y >>= 1;
    x = mul(x, x);
  }
  return res;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 15;
struct edge {
  int v, nxt;
} e[maxn << 1];
int head[maxn], tot, N, p[maxn], scc_idx[maxn], dfn[maxn], low[maxn], T, circle,
    ans = 0, tp = 0, label[maxn];
stack<int> s;
vector<int> block[maxn];
void link(int u, int v) { e[tot].v = v, e[tot].nxt = head[u], head[u] = tot++; }
void tarjan_scc(int u) {
  dfn[u] = low[u] = ++T;
  s.push(u);
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan_scc(v);
      low[u] = min(low[u], low[v]);
    } else if (scc_idx[v] == -1)
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    vector<int> vi;
    ++circle;
    int cnt = 0, haslabel = 0;
    while (1) {
      int x = s.top();
      s.pop();
      ++cnt;
      if (label[x]) haslabel = 1;
      vi.push_back(x);
      scc_idx[x] = circle;
      if (x == u) break;
    }
    if (cnt > 1) {
      if (!haslabel) ++ans;
      ++tp;
      block[tp] = vi;
    } else if (haslabel)
      block[++tp] = vi;
  }
}
int main(int argc, char *argv[]) {
  N = read();
  tot = T = 0;
  int root = -1;
  memset((scc_idx), (-1), sizeof((scc_idx)));
  for (int(i) = (1); (i) <= (N); ++(i)) {
    scanf("%d", p + i);
    head[i] = -1;
    if (p[i] == i) {
      label[i] = 1;
      ++ans;
      root = i;
    }
    link(i, p[i]);
  }
  for (int(i) = (1); (i) <= (N); ++(i))
    if (!dfn[i]) tarjan_scc(i);
  printf("%d\n", ans - (root != -1));
  int st = 1;
  if (root == -1)
    root = block[1][0], st = 2, p[block[1][0]] = block[1][0];
  else
    p[root] = root;
  for (; st <= tp; ++st) {
    int hasroot = 0;
    for (auto it : block[st])
      if (it == root) hasroot = 1;
    if (!hasroot) p[block[st][0]] = root;
  }
  for (int(i) = (1); (i) <= (N); ++(i)) printf("%d ", p[i]);
  printf("\n");
  return 0;
}
