#include <bits/stdc++.h>
using namespace std;
int p[200002] = {0};
int o[200002] = {0};
int iter = 1;
int vi[200002] = {0};
int cyc = 0;
bool r[200002] = {0};
bool c[200002] = {0};
int rs[200002];
int find(int u) {
  vi[u] = iter;
  if (p[u] != u) {
    if (vi[p[u]] == iter) {
      cyc++;
      c[u] = 1;
      p[u] = u;
      return u;
    } else {
      p[u] = find(p[u]);
      return p[u];
    }
  } else {
    return u;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    o[i] = p[i];
  }
  for (int i = 1; i <= n; i++) {
    iter = i;
    r[find(i)] = 1;
  }
  int num = 0;
  int first = -1;
  for (int i = 1; i <= n; i++) {
    if (r[i] == 1) {
      rs[num++] = i;
      if (c[i] != 1) {
        first = i;
      }
    }
  }
  if (num == cyc) {
    cout << num << endl;
    first = rs[0];
  } else {
    cout << num - 1 << endl;
  }
  for (int i = 0; i < num; i++) {
    o[rs[i]] = first;
  }
  for (int i = 1; i <= n; i++) {
    cout << o[i] << ' ';
  }
  cout << endl;
}
