Back to problems

Find Shortest Path in Cyclic Graph

Algorithm · Microsoft · Medium

You are given a directed graph that may contain cycles. Create an algorithm that determines the minimum-distance path between a specified starting vertex and a target vertex. The input consists of a first line containing two integers, n and m, the number of vertices and directed edges. Each of the next m lines contains three integers, u, v, and w, representing a directed edge from u to v with weight w. The final line contains two integers, the starting vertex and the target…

Checking your access…