Dsa
Graphs Dfs
Medium
Minimum Number of Delivery Trips
You need to make deliveries from a warehouse at point 0 to various destinations given in a list of edges. Each edge has a weight representing the time it takes. Determine the minimum time required to deliver to all destinations. If it's impossible to deliver to all destinations, return -1. The input format is as follows:
Input:
- First line: an integer n (1 ≤ n ≤ 100) - the number of destinations.
- Second line: an integer m (1 ≤ m ≤ 200) - the number of edges.
- Next m lines: three integers u, v, t (1 ≤ u, v ≤ n, 1 ≤ t ≤ 100) representing a directed edge from u to v with time t.
Output:
- An integer representing the minimum time to deliver to all destinations or -1 if not all can be reached.
Example:
Input:
4
4
0 1 2
1 2 3
2 3 4
0 3 10
Output:
9
Key concepts
graphsdfsshortest_path
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now