completed solution for minimum triangle path problem