Given a directed weighted graph consisting of N vertices and an array **Edges[][]**, with each row representing two vertices connected by an edge and the weight of that edge, the task is to find the path with the maximum sum of weights from a given source vertex **src** to a given destination vertex **dst**, made up of at most **K** intermediate vertices. If no such path exists, then print **-1**.

**Examples:**

_ N = 3, Edges[][] = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}}, src = 0, dst = 2, K = 0_Input:

_ 500_Output:

Explanation:

_ The path with maximum weight and at most 0 intermediate nodes is of weight 500._Path 0 → 2:

_ N = 3, Edges[][] = {{0, 1, 100}, {1, 2, 100}, {0, 2, 500}}, src = 0, dst = 2, K = 0_Input:

_ 500_Output:

Explanation:

Path 0 → 2:The path with maximum weight and at most 1 intermediate node is of weight 500.

#graph #hash #queue #node #nodejs

9.80 GEEK