#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long N = 2e5 + 7;
const long long MOD = 1e9 + 7;
long long pw(long long b, long long p) {
  b %= MOD;
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
vector<long long> par(N);
long long find(long long x) {
  if (par[x] == x) return x;
  return par[x] = find(par[x]);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    par[i] = i;
  }
  vector<long long> a(n + 1);
  long long cnt = 0, root = 0;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
    if (a[i] == i) {
      root = i;
      cnt++;
    } else {
      long long x = find(i), y = find(a[i]);
      if (x == y) {
        a[i] = i;
        cnt++;
      } else {
        par[i] = a[i];
      }
    }
  }
  if (root == 0) {
    for (long long i = 1; i < n + 1; i++) {
      if (a[i] == i) root = i;
    }
    cnt++;
  }
  cout << cnt - 1 << '\n';
  for (long long i = 1; i < n + 1; i++) {
    cout << ((a[i] == i) ? root : a[i]) << ' ';
  }
  return 0;
}
