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.util.*;

public class Solve{
    static ArrayList<Integer>[] gr;
    static int[] vis;
    static int[] par;
    static int[] p;
    static int[] rank;
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        gr=new ArrayList[n+1];
        rank=new int[n+1];
        for(int i=0;i<=n;i++){
            gr[i]=new ArrayList<>();
        }
        int pcnt=0;
        par=new int[n+1];
        vis=new int[n+1];
        p=new int[n+1];
        for(int i=0;i<=n;i++){
            p[i]=i;
        }
        int pa=0;
        for(int i=1;i<=n;i++){
            par[i]=sc.nextInt();
            if(par[i]==i){pcnt++;
            pa=i;
            }
            else{
               
                gr[i].add(par[i]);
                gr[par[i]].add(i);
            }
             merge(i,par[i]);
        }
        if(pcnt==1){
             System.out.println(0);
             for(int i=1;i<=n;i++)System.out.print(par[i]+" ");
        }
        else{
            int cnt=0;
            for(int i=1;i<=n;i++){
                if(vis[i]==0){
                    dfs(i);
                    cnt++;
                }
            }
            System.out.println(cnt-1);
           
            for(int i=1;i<=n;i++){
              //  System.out.print(p[i]+" ");
            }
         
            for(int i=1;i<=n;i++){
               
                 if(find(i)!=pa){p[i]=pa;
                 par[i]=pa;
                 merge(i,pa);
                 }
                System.out.print(par[i]+" ");
            }
             for(int i=1;i<=n;i++){
                //System.out.print(p[i]+" ");
            }
        }
        
    }
    static void dfs(int n){
        vis[n]=1;
        
        for(int child:gr[n]){
            if(vis[child]==0)dfs(child);
        }
    }
    static int find(int n){
        if(p[n]==n)return n;
         return p[n]=find(p[n]);
    }
    static void merge(int a,int b){
        a=find(a);
        b=find(b);
        if(rank[a]>=rank[b]){
            p[b]=a;
            if(rank[a]==rank[b])rank[a]++;
        }
        else{
            p[a]=b;
        }
    }
}