@@ -0,0 +1,1555 @@
+// Author: Stefan Toman%0A%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Stefan %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner sc = new Scanner(System.in);%0A        int q = sc.nextInt();%0A        for(int qq = 0; qq %3C q; qq++) %7B%0A            int n = sc.nextInt();%0A            int m = sc.nextInt();%0A            List%3CInteger%3E%5B%5D adj = new List%5Bn%5D;%0A            for(int i = 0; i %3C n; i++) %7B%0A                adj%5Bi%5D = new LinkedList%3CInteger%3E();%0A            %7D%0A            for(int i = 0; i %3C m; i++) %7B%0A                int u = sc.nextInt() - 1;%0A                int v = sc.nextInt() - 1;%0A                adj%5Bu%5D.add(v);%0A                adj%5Bv%5D.add(u);%0A            %7D%0A            int s = sc.nextInt() - 1;%0A            int%5B%5D dist = new int%5Bn%5D;%0A            Arrays.fill(dist, -1);%0A            boolean%5B%5D visited = new boolean%5Bn%5D;%0A%0A            Queue%3CInteger%3E qu = new LinkedList%3CInteger%3E();%0A            qu.add(s);%0A            dist%5Bs%5D = 0;%0A            visited%5Bs%5D = false;%0A            while(!qu.isEmpty()) %7B%0A                int c = qu.poll();%0A                for(int neigh: adj%5Bc%5D) %7B%0A                    if(!visited%5Bneigh%5D) %7B%0A                        visited%5Bneigh%5D = true;%0A                        dist%5Bneigh%5D = dist%5Bc%5D + 6;%0A                        qu.add(neigh);%0A                    %7D%0A                %7D%0A            %7D%0A            %0A            for(int i = 0; i %3C n; i++) %7B%0A                if(i != s) %7B%0A                    System.out.print(dist%5Bi%5D);%0A                    System.out.print(i == n - 1 ? %22%5Cn%22 : %22 %22);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

add java solution for shortestreach