#include <bits/stdc++.h>
using namespace std;
int n;
int a[200007];
int ans = 0;
vector<int> p, rank;
int numSets;
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
  if (!isSameSet(i, j)) {
    numSets--;
    int x = findSet(i), y = findSet(j);
    p[x] = y;
  }
}
int numDisjointSets() { return numSets; }
int main() {
  cin >> n;
  numSets = n;
  p.assign(n, 0);
  for (int i = 0; i < n; i++) p[i] = i;
  int root = -1;
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i];
    if (i == a[i] - 1) root = i;
    unionSet(i, a[i] - 1);
  }
  if (root == -1) {
    root = findSet(0);
    a[root] = root + 1;
    ans++;
  }
  cout << numDisjointSets() - 1 + ans << endl;
  for (int i = 0; i < (int)n; i++) {
    if (!isSameSet(root, i)) {
      a[findSet(i)] = root + 1;
      unionSet(findSet(i), root);
    }
  }
  for (int i = 0; i < (int)n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
