Graph - (Floyed-Warshall || BFS)

It Took Me an hour to understand the Input Description :D
btw it can be solved using Floyed-Warshall or BFS.