fix kernel function for find min cost