Update the ending city in array from city which was last visited
i = route [ counter - 1 ] - 1 ; for ( j = 0 ; j < tsp . size ( ) ; j ++ ) { if ( ( i != j ) && tsp [ i ] [ j ] < min ) { min = tsp [ i ] [ j ] ; route [ counter ] = j + 1 ; } } sum += min ;