#include <bits/stdc++.h>
using namespace std;
class dsu {
 public:
  vector<int> p;
  int n;
  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, root = -1;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
    if (p[i] == i and root == -1) root = i;
  }
  dsu uf(n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (uf.get(i) == uf.get(p[i])) {
      if (root == -1) {
        root = i;
        p[i] = root;
        uf.unite(i, root);
        ++cnt;
      } else {
        if (p[i] != root) {
          p[i] = root;
          uf.unite(i, root);
          ++cnt;
        }
      }
    } else
      uf.unite(i, p[i]);
  }
  cout << cnt << '\n';
  for (int i : p) cout << i + 1 << ' ';
}
