3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.file.Paths;
import java.util.*;
public class Main extends PrintWriter {
    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));Main () { super(System.out); }public static void main(String[] args) throws IOException{ Main  d1=new Main   ();d1.main();d1.flush(); }

    void main() throws IOException {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb1 = new StringBuilder();
        int t = 1;
//        t = i(s()[0]);
       while (t-- > 0) {
           String[] s1 = s();
           int n = i(s1[0]);
           int[] a=new int[n + 1];
           String[] s2 = s();
           int root = 0;
           for(int i = 1; i <= n; i++){
               a[i] = i(s2[i - 1]);
               if(i == a[i]) root = a[i];
           }

           int[] vis = new int[n + 1];
           HashMap<Integer, Integer> path = new HashMap<>();
           int ans = 0;
           for(int i=1;i<=n;i++){
             if(vis[i] == 0){
                 vis[i] = 1;
                 flag = 0;
                 path = new HashMap<>();
                 dfs(i, a, path, vis);
                 if(flag == 0) continue;
                 if(root == 0) {
                     root = flag;
                     if(a[flag] != flag){
                         ans++; a[flag] = flag;
                     }
                 }
                 else if(flag == root) continue;
                 else{
                     a[flag] = root;
                     ans++;
                 }
             }
           }
           sb.append(ans + "\n");
           for(int i=1;i <= n;i++){
             sb.append(a[i] + " ");
           }
        }
        System.out.println(sb);
    }
    static int flag = 0;
   static void dfs(int i, int[] a, HashMap<Integer, Integer> path, int[] vis){
        vis[i] = 1;
        if(flag != 0) return;

        if(a[i] == i){
              flag = i; return;
        }else{
            if(path.containsKey(a[i])){
                flag = i;return;
            }else{
                if(vis[a[i]] == 1) {
                    return;
                }
                path.put(i, 0);
                vis[i] = 1;
                dfs(a[i], a, path, vis);
            }
        }
   }
    static String[] s() throws IOException { return s.readLine().trim().split("\\s+"); }
    static int i(String ss) {return Integer.parseInt(ss); }
    static long l(String ss) {return Long.parseLong(ss); }
    public void arr(long[] a,int n) throws IOException {String[] s2=s();for(int i=0;i<n;i++){ a[i]=l(s2[i]); }}
    public void arri(int[] a,int n) throws IOException {String[] s2=s();for(int i=0;i<n;i++){ a[i]=i(s2[i]); }}
}class Pair{
   int end, subject;
    public Pair(int s, int e){
           subject = s; end = e;
    }
}


