#include <bits/stdc++.h>
using namespace std;
int n, root;
int p[200001], cp[200001];
vector<int> adj[200001];
int vis[200001], delta = 0;
void dfs(int u) {
  if (vis[u]) return;
  if (u == root) return;
  vis[u] = 1;
  int& v = p[u];
  if (v == u) {
    if (root == -1)
      root = u;
    else {
      v = root;
      delta++;
    }
  } else {
    dfs(v);
    if (vis[v] == 1) {
      if (root == -1) root = u;
      v = root;
      delta++;
    }
  }
  vis[u] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  root = -1;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    cp[i] = p[i];
    if (i == p[i]) root = i;
  }
  for (int i = 1; i <= n; i++) dfs(i);
  for (int i = 1; i <= n; i++) {
    if (p[i] == i && i != root) {
      p[i] = root;
      delta++;
    }
  }
  delta = 0;
  for (int i = 1; i <= n; i++) delta += (cp[i] != p[i]);
  cout << delta << '\n';
  for (int i = 1; i <= n; i++) cout << p[i] << ' ';
  cout << '\n';
  return 0;
}
