#include <bits/stdc++.h>
using namespace std;
vector<int> v[200001];
int par[200001], parent[200001];
int find(int i) {
  if (parent[i] == -1) return i;
  return parent[i] = find(parent[i]);
}
void Union(int x, int y) {
  int xset = find(x);
  int yset = find(y);
  parent[xset] = yset;
}
int main() {
  int i, j, k, n, m;
  cin >> n;
  int flg[200001] = {0};
  int cnt = 0;
  for (i = 0; i <= n; i++) {
    parent[i] = -1;
  }
  for (i = 1; i <= n; i++) {
    int p;
    cin >> p;
    par[i] = p;
    int x = find(p);
    int y = find(i);
    if (x == y) {
    } else {
      parent[y] = x;
    }
  }
  int arr[1];
  arr[0] = 0;
  k = 0;
  int fr = 0;
  for (i = 1; i <= n; i++) {
    if (i == par[i] && k == 0) {
      arr[0] = i;
      k++;
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    if (i == arr[0]) continue;
    if (parent[i] == -1 && k == 0) {
      arr[0] = i;
      par[i] = arr[0];
      parent[i] = arr[0];
      cnt++;
      k++;
    } else if (parent[i] == -1) {
      par[i] = arr[0];
      cnt++;
      parent[i] = arr[0];
    }
  }
  cout << cnt << endl;
  for (i = 1; i <= n; i++) cout << par[i] << " ";
  cout << endl;
  return 0;
}
