#include <bits/stdc++.h>
using namespace std;
int p[200001], a[200001], b[200001];
int Find(int x) {
  if (a[x] == x) return x;
  return Find(a[x]);
}
void Union(int x, int y) {
  x = Find(x), y = Find(y);
  if (x != y) a[x] = y;
}
int main() {
  int n, cnt = 0, sgn = 0;
  cin >> n;
  for (int i = 0; i <= n; ++i) a[i] = i, b[i] = false;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (p[i] != i && Find(i) == Find(p[i]))
      p[i] = i, sgn++, b[i] = true;
    else
      Union(i, p[i]);
  }
  int flag = 0, root = 0, tmp = 0;
  for (int i = 1; i <= n; ++i) {
    if (p[i] == i) {
      if (b[i] == false) {
        root = i, flag = 1;
        break;
      }
      tmp = i;
    }
  }
  if (flag != 1) root = tmp, cnt++;
  flag = 0;
  for (int i = 1; i <= n; ++i) {
    if (i != root && p[i] == i) {
      tmp = Find(i);
      a[tmp] = root;
      p[i] = root;
      cnt++, flag++;
    }
  }
  cout << cnt << endl << p[1];
  for (int i = 2; i <= n; ++i) cout << " " << p[i];
  cout << endl;
  return 0;
}
