#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long mod = 1000000007;
int p[N], visit[N], tpar[N], root, p1[N];
vector<int> g[N];
void dfs(int node, int par) {
  visit[node] = 1;
  if (p[node] == node) root = node;
  for (int i = 0; i < g[node].size(); i++) {
    int u = g[node][i];
    if (u == par) continue;
    if (visit[u]) {
      root = u;
      continue;
    }
    dfs(u, node);
  }
}
vector<int> roots;
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    p1[i] = p[i];
    g[p[i]].push_back(i);
    g[i].push_back(p[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visit[i] == 0) {
      dfs(i, -1);
      roots.push_back(root);
    }
  }
  int mroot = 0;
  for (int i = 0; i < roots.size(); i++) {
    if (p[roots[i]] == roots[i]) {
      mroot = roots[i];
    }
  }
  p[roots[0]] = roots[0];
  if (mroot == 0) {
    mroot = roots[0];
  }
  for (int i = 0; i < roots.size(); i++) {
    if (roots[i] != mroot) {
      p[roots[i]] = mroot;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] != p1[i]) ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
