#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
using namespace std;
const int maxn = (int)2e5 + 13;
const long long INFL = 9223372036854775807;
const int INF = 2147483646;
const long long MOD = (int)1e9 + 21;
const long long base = 257;
vector<int> gr[maxn];
bool vis[maxn];
void dfs(int v, vector<int> &c, int &r, int p = -1) {
  vis[v] = 1;
  c.push_back(v);
  for (auto t : gr[v]) {
    if (!vis[t] && t != p) {
      dfs(t, c, r, v);
    } else if (t != p) {
      r = t;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n + 1);
  vector<int> roots;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    if (i != p[i])
      gr[i].push_back(p[i]), gr[p[i]].push_back(i);
    else
      roots.push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      vector<int> v;
      int r = -1;
      dfs(i, v, r);
      if (r != -1 && roots.size() != 0)
        p[r] = roots[0], ans++;
      else if (r != -1 && roots.size() == 0)
        p[r] = r, ans++, roots.push_back(r);
    }
  }
  for (int i = 1; i < roots.size(); ++i) {
    p[roots[i]] = roots[0];
    ans++;
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; ++i) cout << p[i] << " ";
  return 0;
}
