#include <bits/stdc++.h>
using namespace std;
struct node {
  int par;
  int rank;
};
node br[2000001];
int ar[2000001];
int find(int a) {
  if (br[a].par == -1) return a;
  return find(br[a].par);
}
void merge(int a, int b) {
  if (br[a].rank < br[b].rank) swap(a, b);
  br[a].rank += br[b].rank;
  br[b].par = a;
}
int getCount(int n) {
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (br[i].par == -1) cnt++;
  return cnt;
}
int main() {
  int n, cnt = 0, a, b;
  vector<int> v, u;
  cin >> n;
  for (int i = 1; i <= n; i++) br[i].par = -1, br[i].rank = 1;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    if (ar[i] == i)
      v.push_back(i);
    else {
      a = find(i), b = find(ar[i]);
      if (a == b)
        u.push_back(i);
      else
        merge(a, b);
    }
  }
  if (v.size() == 0) {
    cnt = getCount(n);
    for (int i = 0; i < u.size(); i++) ar[u[i]] = u[0];
  } else {
    cnt = getCount(n) - 1;
    for (int i = 1; i < v.size(); i++) ar[v[i]] = v[0];
    for (int i = 0; i < u.size(); i++) ar[u[i]] = v[0];
  }
  cout << cnt << '\n';
  for (int i = 1; i <= n; i++) cout << ar[i] << ' ';
}
