Who gets the next rider?
Riders leave from the café. Each order has a destination and a deadline. Combine the structures you built: a graph of the town, BFS for travel distance, and a priority queue to always dispatch the order with the least slack.
Plan the dispatcher
Break the problem into the structures you know. Build an adjacency list from the roads. Run BFS once from the café to get every destination's distance in hops, then multiply by five minutes. For each order, slack is the deadline minus the travel time. A priority queue ordered by slack hands out the most urgent order first.
- Graph: Map of town → neighbours, both directions.
- Distances: one BFS from "Cafe" — O(V + E).
- Slack: deadline - hops * 5.
- Order: priority queue by slack, ties by id.
- Unreachable destinations: decide and document what happens (skip or report).
Compute everything that doesn't depend on the order once, before the loop over orders.