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

public class FixATree {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), root = -1;
            DSU dsu = new DSU(n);
            int[] res = new int[n];
            ArrayList<Integer> np = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int parent = inp.nextInt() - 1;
                if (i == parent && root == -1) {
                    root = i;
                    res[i] = i;
                } else if (i == parent || dsu.sameSet(i, parent)) {
                    np.add(i);
                } else {
                    dsu.union(i, parent);
                    res[i] = parent;
                }
            }
            out.println(np.size());
            if (root == -1) {
                root = np.remove(0);
                res[root] = root;
            }
            for (int i: np) res[i] = root;
            for (int i: res) out.print((i+1) + " ");
        }

        public class DSU {
            int[] p;

            public DSU(int n) {
                p = new int[n];
                clear();
            }

            private void clear() {
                for (int i = 0; i < p.length; i++) p[i] = i;
            }

            public int get(int x) {
                int x2 = x;
                while (x2 != p[x2]) x2 = p[x2];
                while (x != p[x]) {
                    int t = p[x];
                    p[x] = x2;
                    x = t;
                }
                return x2;
            }

            public void union(int a, int b) {
                a = get(a);
                b = get(b);
                p[a] = b;
            }

            public boolean sameSet(int a, int b) {
                return get(a) == get(b);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}