#include <bits/stdc++.h>
using namespace std;
long long int n, m, ar[1000005], sum, t, rt = 0, mark[1000005], vis[1000005],
                                         gl;
bool flag = 0;
void f2(int ind) {
  if (mark[ind] || vis[ind] == 0) return;
  mark[ind] = 1;
  vis[ind] = 0;
  f2(ar[ind]);
}
void f(int ind) {
  if (ind == rt || mark[ind]) {
    return;
  }
  if (vis[ind]) {
    if (!rt)
      rt = ind;
    else {
      sum++, gl = ind;
    }
    return;
  }
  vis[ind] = 1;
  if (mark[ar[ind]]) {
  }
  f(ar[ind]);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> ar[i];
  for (long long int i = 1; i <= n; i++) {
    if (ar[i] != i) continue;
    rt = i;
  }
  for (long long int i = 1; i <= n; i++)
    if (ar[i] == i && i != rt) {
      sum++, ar[i] = rt;
    }
  for (int i = 1; i <= n; i++) {
    if (mark[i] || i == rt) continue;
    flag = 0;
    int fl = 0;
    if (!rt) fl = 1;
    f(i);
    f2(i);
    if (fl == 1) sum++, ar[rt] = rt, fl = 0;
    ;
    if (gl) ar[gl] = rt, gl = 0;
  }
  cout << sum << "\n";
  for (long long int i = 1; i <= n; i++) cout << ar[i] << " ";
}
