There should be an edge from i to a and a should not be same as either i or j
if ( graph [ i , a ] != INF && i != a && j != a && sp [ a , j , e - 1 ] != INF ) sp [ i , j , e ] = Math . Min ( sp [ i , j , e ] , graph [ i , a ] + sp [ a , j , e - 1 ] ) ; } } } } } return sp [ u , v , k ] ; }