#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279502884L;
const long double E = 2.718281828459045235360287471352662498L;
const long double EPS = 1e-12L;
int n, root;
bool graph;
int p[204800];
set<int> r;
vector<int> t, h;
vector<int> g[204800];
bool u[204800];
void dfs(int s, int p) {
  if (r.count(s)) {
    root = s;
  }
  u[s] = true;
  for (int i = 0; i < g[s].size(); ++i) {
    if (!u[g[s][i]]) {
      dfs(g[s][i], s);
    } else {
      if (g[s][i] != p) {
        graph = true;
        root = g[s][i];
      }
    }
  }
}
bool check(int v) {
  root = -1;
  graph = false;
  dfs(v, v);
  return graph;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(11);
  cout.setf(ios::fixed);
  cin >> n;
  memset(u, false, 204800);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    if (p[i] == i + 1) {
      r.insert(i);
    } else {
      g[i].push_back(p[i] - 1);
      g[p[i] - 1].push_back(i);
    }
  }
  for (int j = 0; j < n; ++j) {
    if (!u[j]) {
      bool tt = check(j);
      if (tt) {
        h.push_back(root);
      } else {
        t.push_back(root);
      }
    }
  }
  if (t.size() == 0) {
    cout << h.size() << endl;
    p[h[0]] = h[0] + 1;
    for (int i = 1; i < h.size(); ++i) {
      p[h[i]] = p[h[0]];
    }
    for (int i = 0; i < n; ++i) {
      cout << p[i] << ' ';
    }
  } else {
    cout << t.size() + h.size() - 1 << endl;
    for (int i = 1; i < t.size(); ++i) {
      p[t[i]] = p[t[0]];
    }
    for (int j = 0; j < h.size(); ++j) {
      p[h[j]] = p[t[0]];
    }
    for (int i = 0; i < n; ++i) {
      cout << p[i] << ' ';
    }
  }
  return 0;
}
