#include <bits/stdc++.h>
using namespace std;
void dfs(long long visited[], long long arr[], long long curr) {
  if (arr[curr] != curr) {
    if (visited[arr[curr]] == 0) {
      visited[arr[curr]] = 1;
      dfs(visited, arr, arr[curr]);
    } else {
      arr[curr] = curr;
    }
  }
}
int main() {
  long long n;
  cin >> n;
  long long arr[n + 1], parent[n + 1], visited[n + 1];
  long long z = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    parent[i] = i;
    visited[i] = 0;
    if (i == arr[i]) z = i;
  }
  long long marker = 0, x, counter = 0;
  for (long long i = 1; i <= n; i++) {
    marker++;
    x = i;
    while (!visited[x]) {
      visited[x] = marker;
      x = arr[x];
    }
    if (visited[x] == marker) {
      if (!z) {
        z = x;
        counter++;
        arr[x] = x;
      }
      if (x != z) {
        counter++;
        arr[x] = z;
      }
    }
  }
  cout << counter << endl;
  for (long long i = 1; i <= n; i++) cout << arr[i] << " ";
}
