#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 2e5 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
int fa[N];
int vis[N];
vector<int> root, cir;
int tim;
void dfs(int x) {
  if (vis[x] == tim) {
    cir.push_back(x);
    return;
  }
  if (vis[x]) return;
  vis[x] = tim;
  dfs(fa[x]);
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &fa[i]);
      vis[i] = 0;
    }
    root.clear();
    cir.clear();
    for (int i = 1; i <= n; ++i) {
      if (fa[i] == i) {
        root.push_back(i);
        vis[i] = -1;
      }
    }
    tim = 0;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        ++tim;
        dfs(i);
      }
    int ans = 0;
    int rt;
    if (root.size())
      rt = root[0];
    else
      rt = cir[0];
    for (int i = 0; i < root.size(); ++i) {
      int x = root[i];
      if (fa[x] != rt) {
        fa[x] = rt;
        ++ans;
      }
    }
    for (int i = 0; i < cir.size(); ++i) {
      int x = cir[i];
      if (fa[x] != rt) {
        fa[x] = rt;
        ++ans;
      }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i) printf("%d ", fa[i]);
    puts("");
  }
  return 0;
}
