fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner in =new Scanner(System.in);
  13. int n = in.nextInt();
  14. int w[][] = new int[n][n];
  15. for( int i = 0 ; i < n ; i++ ){
  16. for( int j = 0 ; j < n ; j++ ){
  17. w[i][j] = in.nextInt();
  18. }
  19. }
  20.  
  21. for( int k = 0 ; k < n ; k++ ){
  22. for( int i = 0 ; i<n ; i++ ){
  23. for( int j=0 ; j<n ; j++ ){
  24. w[i][j] = Math.min(w[i][j], w[i][k] + w[k][j]);
  25. }
  26. }
  27. }
  28.  
  29. for( int i = 0 ; i < n ; i++ ){
  30. for( int j = 0 ; j < n ; j++ ){
  31. System.out.print(w[i][j] + " ");
  32. }
  33. System.out.println();
  34. }
  35. }
  36. }
Internal error #stdin #stdout 0.06s 711680KB
stdin
4
0 5 9 100
100 0 2 8
100 100 0 7
4 100 100 0
stdout
Standard output is empty