We’re preparing your current view and syncing the latest data.
Design a graph data structure that allows you to add directed, weighted edges and calculate the shortest path between any two nodes efficiently. Implement functions to add edges and to return the shortest path distance between two given nodes.
Methods to add edges and a method to query shortest path distance are provided. Inputs include source and destination nodes and the weight for edges.
Return the shortest path distance for the query, or -1 if no such path exists.
All node values are integers within a certain range. Edge weights are positive integers. Graph size and number of edges are within reasonable memory and time limits for efficient implementations.