SergeyPGUTI

11.1.4

Apr 16th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. public class Ex_1_4 {
  6.     public static void main(String args[]) {
  7.         int n;
  8.         int a,b,c;
  9.         int way[]=new int[3];
  10.         int min=Integer.MAX_VALUE;
  11.         Scanner sc = new Scanner(System.in);
  12.         n = sc.nextInt();
  13.  
  14.         AdjacencyMatrix matrix = new AdjacencyMatrix(n, n);
  15.         matrix.consoleRead();
  16.         for (int i = 0; i < n; i++)
  17.             for (int j = 0; j < n; j++)
  18.                 for (int k = 0; k < n; k++) {
  19.                     a = matrix.get(i, j);
  20.                     b = matrix.get(i, k);
  21.                     c = matrix.get(k, j);
  22.                     if (a==0 || b==0 || c==0)
  23.                         continue;
  24.                     if (a+b+c<min)
  25.                     {
  26.                         min=a+b+c;
  27.                         way[0]=i+1;
  28.                         way[1]=j+1;
  29.                         way[2]=k+1;
  30.                     }
  31.                 }
  32.         System.out.println(way[0]+" "+way[1]+" "+way[2]);
  33.     }
  34. }
Add Comment
Please, Sign In to add comment