#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int p[N], edn, n, m, a[N], deg[N];
vector<int> vec[N];
int num = 0;
struct Edge {
  int v, next;
  Edge() {}
  Edge(int v, int next) : v(v), next(next) {}
} edge[N];
void addedge(int u, int v) {
  edge[edn] = Edge(v, p[u]);
  p[u] = edn++;
}
queue<int> q;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    deg[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 0) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    deg[a[x]]--;
    if (!deg[a[x]]) q.push(a[x]);
  }
  int root = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i]) {
      num++;
      vec[num].push_back(i);
      int x = a[i];
      deg[x] = 0;
      while (x != i) {
        vec[num].push_back(x);
        deg[x] = 0;
        x = a[x];
      }
      if (vec[num].size() == 1) root = vec[num][0];
    }
  }
  if (!root) root = vec[1][0];
  int cnt = 0;
  for (int i = 1; i <= num; i++) {
    int x = vec[i][0];
    if (a[x] != root) {
      cnt++;
      a[x] = root;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) printf("%d%c", a[i], i == n ? '\n' : ' ');
  return 0;
}
