updated recursive function when solving cross path