#include <bits/stdc++.h>
int parent[200001];
int forrest[200001];
int count;
int order;
int root;
void g(int index) {
  ++order;
  if (parent[index] == index) {
    ++count;
    forrest[index] = order;
    parent[index] = root;
    return;
  }
  forrest[index] = order;
  index = parent[index];
  while (not forrest[index]) {
    forrest[index] = order;
    index = parent[index];
  }
  if (forrest[index] == order) {
    parent[index] = root;
    ++count;
  }
}
void f() {
  int index;
  ++order;
  index = parent[1];
  forrest[1] = order;
  while (0 == forrest[index]) {
    forrest[index] = order;
    index = parent[index];
  }
  root = index;
  ++count;
  parent[index] = index;
}
int main() {
  int index;
  int n;
  std::cin >> n;
  for (index = 1; index <= n; ++index) {
    std::cin >> parent[index];
  }
  for (index = 1; index <= n; ++index) {
    if (parent[index] == index) {
      root = index;
      forrest[root] = (++order);
      break;
    }
  }
  if (0 == root) {
    f();
  }
  for (index = 1; index <= n; ++index) {
    if (not forrest[index]) {
      g(index);
    }
  }
  std::cout << count << std::endl;
  for (index = 1; index <= n; ++index) {
    std::cout << parent[index] << ' ';
  }
  return 0;
}
