#include <bits/stdc++.h>
using namespace std;
int arr[500005];
int visited[500005];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> arr[i];
    visited[i] = 0;
  }
  int root = -1;
  for (int i = 1; i < n + 1; i++) {
    if (i == arr[i]) root = i;
  }
  int time = 0;
  for (int i = 1; i < n + 1; i++) {
    if (visited[i] != 0) continue;
    time++;
    visited[i] = time;
    int u = arr[i];
    while (visited[u] == 0) {
      visited[u] = time;
      u = arr[u];
    }
    if (visited[u] == time) {
      if (root == -1) root = u;
      if (arr[u] != root) {
        ans++;
        arr[u] = root;
      }
    }
  }
  cout << ans << "\n";
  for (int i = 1; i < n + 1; i++) cout << arr[i] << " ";
}
