COZID-Chef and Food Delivery

i have been trying to solve this question for days. please suggest some hints or solutions.

Actually, You have to find sum of distances for every node. I think there can be two approaches, Dijkstra’s algorithm, and strategic leaf removing.