#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using lld = long double;
using vll = int64_t;
class DSU {
 public:
  int n, comp;
  int *par, *sz;
  DSU(int k) {
    par = new int[k];
    sz = new int[k];
    n = k;
    init();
  }
  void init() {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
    comp = n;
  }
  bool _union(int a, int b) {
    if (_is_connected(a, b)) return false;
    int root1 = _find(a);
    int root2 = _find(b);
    if (root1 == root2) return false;
    if (sz[root1] < sz[root2]) {
      sz[root2] += sz[root1];
      par[root1] = par[root2];
    } else {
      sz[root1] += sz[root2];
      par[root2] = par[root1];
    }
    comp--;
    return true;
  }
  int _find(int a) {
    int tmp = a;
    while (tmp != par[tmp]) {
      tmp = par[tmp];
    }
    while (a != par[a]) {
      int z = par[a];
      par[a] = tmp;
      a = z;
    }
    return a;
  }
  bool _is_connected(int a, int b) { return _find(a) == _find(b); }
  int get_size(int i) { return sz[_find(i)]; }
};
const int N = 2e5 + 1;
vector<int> ar(N, 0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  DSU d(n);
  int root = -1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    ar[i]--;
    if (ar[i] == i) root = i;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ar[i] == i and root == -1) {
      root = i;
      continue;
    }
    if (ar[i] == i && i != root) {
      ans++;
      ar[i] = root;
      continue;
    }
    if (d._is_connected(i, ar[i]) && i != root) {
      if (root == -1)
        root = ar[i] = i;
      else
        ar[i] = root;
      ans++;
      d._union(i, ar[i]);
    } else {
      d._union(i, ar[i]);
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    cout << ar[i] + 1 << " ";
  }
  return 0;
}
