#include <bits/stdc++.h>
using namespace std;
int par[200006], vis[200006];
bool C[200006];
int cyc;
bool dfs(int node) {
  if (vis[node] == 2) return false;
  if (vis[node] == 1) {
    cyc = node;
    return true;
  }
  vis[node] = 1;
  bool ret = false;
  if (par[node] != node) ret = dfs(par[node]);
  vis[node] = 2;
  return ret;
}
int main() {
  int N, i, ans, root;
  while (scanf("%d", &N) != EOF) {
    for (i = 1; i <= N; i++) {
      scanf("%d", &par[i]);
      vis[i] = 0, C[i] = false;
    }
    ans = 0;
    root = -1;
    for (i = 1; i <= N; ++i) {
      if (par[i] == i && C[i] == 0) {
        root = i;
        vis[i] = 2;
        continue;
      }
      if (vis[i] == 2)
        continue;
      else if (dfs(i)) {
        ++ans;
        par[cyc] = cyc;
        C[cyc] = true;
      }
    }
    if (root == -1) {
      for (i = 1; i <= N; ++i) {
        if (par[i] == i) {
          root = i;
          break;
        }
      }
    }
    for (i = 1; i <= N; ++i) {
      if (par[i] != i || i == root) continue;
      par[i] = root;
      if (C[i] == false) ++ans;
    }
    printf("%d\n", ans);
    for (i = 1; i <= N; ++i) printf("%d ", par[i]);
    puts("");
  }
  return 0;
}
