#include <bits/stdc++.h>
using namespace std;
int f[204800], p[204800], n, rt = 0, m;
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  cin >> n;
  int i;
  for (i = 1; i <= n; ++i) f[i] = i;
  for (i = 1; i <= n; ++i) {
    cin >> p[i];
    f[find(i)] = find(p[i]);
    if (p[i] == i) rt = i;
  }
  int sum = 0;
  for (i = 1; i <= n; ++i)
    if (find(i) == i) sum = sum + 1;
  cout << sum - !!rt << endl;
  for (i = 1; i <= n; ++i) {
    int x = p[i];
    if (find(i) == i && i != rt) {
      if (!rt) rt = i;
      x = rt;
    }
    cout << x << " ";
  }
}
