#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long MOD = 1e9 + 7;
struct UF {
  vector<int> data;
  UF(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int(i) = 0; (i) < (n); ++(i)) {
    cin >> a[i];
    --a[i];
  }
  UF uf(n);
  vector<int> vs;
  int root = -1;
  for (int(i) = 0; (i) < (n); ++(i)) {
    if (i == a[i] && root < 0) {
      root = i;
    } else if (!uf.unite(i, a[i])) {
      vs.push_back(i);
    }
  }
  if (root < 0) {
    root = vs.back();
  }
  cout << vs.size() << endl;
  vector<int> re = a;
  for (int v : vs) re[v] = root;
  for (int(i) = 0; (i) < (n); ++(i)) cout << re[i] + 1 << " ";
  cout << endl;
  return 0;
}
