I solve the traveling salesman problem by the branches and borders method. There was a snag, it is not so much connected with the code, as with the understanding of the algorithm. enter image description here

With the first two lines - everything is clear, but take, for example, line 3:

30, 0, М, 40, 0 

The algorithm says

for all cells of the matrix with zero elements, we replace alternately zeroes on M

we get:

 30, М, М, 40, М 

it turns out that the minimum element = 30 , i.e. di=30 , and in the table it is 0 . The question is, where does 0 come from? Or do we replace only the first 0 with М , and do not touch the other, in case there are more than one in the line?

A bit of code:

 for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) if (_Mass[i, j] == "0") _Mass[i, j] = (MinDi[i] + MinDj[j]).ToString(); 

0