Guest User

Untitled

a guest
Jun 25th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.     public static Tuple<int[,], int[,]> findPath(int[,] matrix, int factoryCount){
  2.  
  3.         int[,] dist = new int[factoryCount, factoryCount];
  4.         int[,] next = new int[factoryCount, factoryCount];
  5.  
  6.         for(int x = 0; x < factoryCount; x++){
  7.             for(int y = 0; y < factoryCount; y++){
  8.                 dist[x,y] = matrix[x,y];
  9.                 next[x,y] = y;
  10.             }
  11.         }
  12.  
  13.         for(int z = 0; z < factoryCount; z++){
  14.             dist[z,z] = 0;
  15.             next[z,z] = z;
  16.         }
  17.  
  18.         for(int k = 0; k < factoryCount; k++){
  19.             for(int i = 0; i < factoryCount; i++){
  20.                 for(int j = 0; j < factoryCount; j++){
  21.                     if (dist[i, j] > dist[i, k] + dist[k, j]){
  22.  
  23.                         dist[i, j] = dist[i, k] + dist[k, j];
  24.                         next[i, j] = next[i, k];
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.        
  30.         return new Tuple<int[,], int[,]>(dist, next);
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment