2023AlgoGraph Traversal
8 minMediumCODE2 marks
Implement BFS distance
Write a function shortest_distance(graph, source, target) that returns the number of edges in the shortest unweighted path. Return -1 if unreachable.
input: {0:[1,2],1:[3],2:[3],3:[]}, 0, 3 => output: 2
input: {0:[1],1:[],2:[0]}, 0, 2 => output: -1