@@ -0,0 +1,2813 @@
+import java.util.ArrayDeque;%0Aimport java.util.Arrays;%0Aimport java.util.Queue;%0A%0A/**%0A * Date: 11/29/15%0A * Time: 4:18 PM%0A *%0A * @author Artem Prigoda%0A */%0Apublic class TheTwoRoutes %7B%0A%0A    public int breadthFirstSearch(Graph graph, int root) %7B%0A        Queue%3CInteger%3E candidates = new ArrayDeque%3C%3E();%0A        candidates.add(root);%0A        while (!candidates.isEmpty()) %7B%0A            Integer candidate = candidates.poll();%0A            for (int i = 0; i %3C graph.length(); i++) %7B%0A                if (graph.get(candidate, i) == Integer.MAX_VALUE) %7B%0A                    graph.set(candidate, i, graph.get(root, candidate) + 1);%0A                    graph.set(i, candidate, graph.get(root, candidate) + 1);%0A                    candidates.add(i);%0A                %7D%0A            %7D%0A        %7D%0A        return 0;%0A    %7D%0A%0A    private static class Graph %7B%0A        private int%5B%5D%5B%5D vertexes;%0A%0A        public Graph(int size) %7B%0A            this.vertexes = new int%5B5%5D%5B5%5D;%0A        %7D%0A%0A        public int length() %7B%0A            return vertexes.length;%0A        %7D%0A%0A        public int get(int i, int j) %7B%0A            return vertexes%5Bi%5D%5Bj%5D;%0A        %7D%0A%0A        public void set(int i, int j, int value) %7B%0A            vertexes%5Bi%5D%5Bj%5D = value;%0A        %7D%0A%0A        public int%5B%5D adjacent(int i) %7B%0A            return vertexes%5Bi%5D;%0A        %7D%0A%0A        public Graph copy() %7B%0A            Graph copy = new Graph(length());%0A            for (int i = 0; i %3C length(); i++) %7B%0A                System.arraycopy(vertexes%5Bi%5D, 0, copy.vertexes%5Bi%5D, 0, length());%0A            %7D%0A            return copy;%0A        %7D%0A%0A        public void print() %7B%0A            for (int%5B%5D row : vertexes) %7B%0A                System.out.println(Arrays.toString(row));%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int size = 5;%0A        Graph original = new Graph(size);%0A        original.vertexes%5B0%5D%5B1%5D = Integer.MAX_VALUE;%0A        original.vertexes%5B0%5D%5B4%5D = Integer.MAX_VALUE;%0A        original.vertexes%5B1%5D%5B3%5D = Integer.MAX_VALUE;%0A        original.vertexes%5B2%5D%5B4%5D = Integer.MAX_VALUE;%0A        original.vertexes%5B3%5D%5B4%5D = Integer.MAX_VALUE;%0A%0A        original.print();%0A        System.out.println(%22%22);%0A%0A        Graph copy = original.copy();%0A        new TheTwoRoutes().breadthFirstSearch(copy, 0);%0A        copy.print();%0A%0A        Graph road = original.copy();%0A        for (int i = 0; i %3C original.length(); i++) %7B%0A            for (int j = 0; j %3C original.length(); j++) %7B%0A                if (i == j) %7B%0A                    continue;%0A                %7D%0A                if (road.get(i, j) == 0) %7B%0A                    road.set(i, j, Integer.MAX_VALUE);%0A                %7D else %7B%0A                    road.set(i, j, 0);%0A                %7D%0A            %7D%0A        %7D%0A        System.out.println(%22%22);%0A%0A        new TheTwoRoutes().breadthFirstSearch(road, 0);%0A        road.print();%0A    %7D%0A%7D%0A

Add two routes