#include <bits/stdc++.h>
using namespace std;
const long long OO = 1LL << 60;
long long mod = 1000000007;
double eps = 1e-6;
int a[200009];
int par[200009];
int root(int v) { return par[v] < 0 ? v : (par[v] = root(par[v])); }
void merge(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (par[y] < par[x]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) par[i] = -1;
  bool hasRoot = false;
  int TreeRoot = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == i && !hasRoot) {
      hasRoot = true;
      TreeRoot = i;
    } else if (root(i) == root(a[i]))
      a[i] = -1;
    else
      merge(i, a[i]);
  }
  int ans = 0;
  if (!hasRoot) {
    for (int i = 1; i <= n; i++)
      if (a[i] == -1) {
        TreeRoot = i;
        break;
      }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == -1) a[i] = TreeRoot, ans++;
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; i++) {
    if (i != 1) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
