Optimal Network Routing

Can someone tell me the idea to approach this problem. I couldn’t figure out the proper logic.

Link: https://www.hackerrank.com/contests/hack-the-interview-iv-apac/challenges/optimal-path-1