#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int n, p[N], ck[N];
vector<int> pset(N, 0);
vector<int> event;
void init() {
  for (int i = (1), _b = (n); i <= _b; i = i + 1) pset[i] = i;
}
int finds(int x) { return (pset[x] == x ? x : pset[x] = finds(pset[x])); }
int same(int x, int y) { return finds(x) == finds(y); }
void unions(int x, int y) { pset[finds(x)] = finds(y); }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  init();
  for (int i = (1), _b = (n); i <= _b; i = i + 1) {
    cin >> p[i];
    if (p[i] == i) continue;
    if (same(i, p[i])) {
      p[i] = 0;
      event.push_back(i);
    } else
      unions(i, p[i]);
  }
  int head = -1;
  bool ok = true;
  for (int i = (1), _b = (n); i <= _b; i = i + 1) {
    if (p[i] == i && ok == true) {
      head = i;
      ok = false;
      continue;
    }
    if (p[i] == i && ok == false) {
      event.push_back(i);
      p[i] = 0;
    }
  }
  int cnt = 0;
  if (head == -1) head = event[0];
  if (p[head] == 0) p[head] = head, cnt++;
  for (int i = 0; i < event.size(); ++i) {
    int v = event[i];
    if (same(head, v) == false) {
      cnt++;
      p[v] = head;
      unions(v, head);
    }
  }
  cout << cnt << '\n';
  for (int i = 1; i <= n; ++i) cout << p[i] << ' ';
}
