#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 9;
const int INF = 1e9 + 9;
int tab[MAX_N];
int P[MAX_N];
vector<int> G[MAX_N];
int lead[MAX_N];
int component[MAX_N];
bitset<MAX_N> been;
int compcnt = 1;
int root = -1;
int sol = 0;
int n;
void DFS(int v, int comp) {
  component[v] = comp;
  for (int i = 0; i < G[v].size(); ++i) {
    int u = G[v][i];
    if (component[u] == 0) DFS(u, comp);
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &tab[i]);
    P[i] = tab[i];
    G[tab[i]].push_back(i);
    G[i].push_back(tab[i]);
    if (root == -1 && tab[i] == i) root = i;
  }
  if (root != -1) {
    lead[compcnt] = root;
    DFS(root, compcnt);
  }
  ++compcnt;
  for (int i = 1; i <= n; ++i) {
    if (component[i] == 0) {
      lead[compcnt] = i;
      DFS(i, compcnt++);
    }
  }
  for (int i = 2; i < compcnt; ++i) {
    int v = lead[i];
    while (!been[v]) {
      been[v] = true;
      v = P[v];
    }
    if (root == -1) root = v;
    tab[v] = root;
    ++sol;
  }
  printf("%d\n", sol);
  for (int i = 1; i < n; ++i) printf("%d ", tab[i]);
  printf("%d\n", tab[n]);
  return 0;
}
