#include <bits/stdc++.h>
using namespace std;
int parent[200500], arr[200500];
int FindParent(int node) {
  return parent[node] == node ? node : parent[node] = FindParent(parent[node]);
}
bool SameParent(int x, int y) { return FindParent(x) == FindParent(y); }
void JoinSets(int x, int y) {
  if (SameParent(x, y)) return;
  int par1 = FindParent(y);
  int par2 = FindParent(x);
  parent[par2] = par1;
}
int main() {
  int n;
  cin >> n;
  vector<int> roots;
  int sum = 0, ans = 0;
  for (int i = 1; i <= n; i++) parent[i] = i;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (FindParent(i) == FindParent(x) && x != i) {
      roots.push_back(i);
      parent[FindParent(i)] = i;
      arr[i] = i;
    } else if (x == i) {
      ans = i;
      arr[i] = i;
      roots.push_back(i);
    } else {
      JoinSets(i, x);
      arr[i] = x;
    }
  }
  for (int i = 0; i < roots.size(); i++) {
    if (roots[i] != ans && ans != 0) arr[roots[i]] = ans;
    if (ans == 0 && i + 1 < roots.size()) arr[roots[i]] = roots[i + 1];
  }
  if (ans)
    cout << roots.size() - 1 << endl;
  else
    cout << roots.size() << endl;
  for (int i = 1; i <= n; i++) cout << arr[i] << " ";
  return 0;
}
