Emergency Response
Time limit1sMemory limit128 MB
Given a directed weighted graph, answer multiple queries: the shortest travel time from any of several start nodes to one crime intersection.
- Level
Medium4 of 10
- Topics
- Graph, Shortest path, Greedy, Implementation
- Solved
- No attempts yet
Problem
When a crime happens, it is important that the emergency police response reach the crime scene as quickly as possible. That lets them secure as much evidence as possible, perhaps save the victim, and maybe even catch the perpetrator. To achieve this, it is often useful to dispatch emergency vehicles from several different starting locations at once, so as to avoid traffic delays and the like. In this problem you must write a program that computes when the first of several vehicles will reach the crime scene.
The city is described by intersections and roads. Each road is given by its starting intersection , its ending intersection , and the travel time . If a pair does not appear in the list, there is no direct road from to . Roads are directed, so the time from to need not equal the time from to (a street may be one-way, or have different traffic in each direction). You are also given the starting intersection of every car and the destination (crime) intersection, each as an intersection number.
Input
The first line contains three numbers . is the number of intersections, is the number of roads, and is the number of scenarios that follow. This is followed by lines, each describing one road with three numbers: the starting intersection , the ending intersection , and the travel time (a floating point number).
Then come scenarios. The first line of each scenario contains two numbers . is the intersection at which the crime happened and is the number of cars dispatched. The next line contains numbers separated by single spaces: the starting intersections of the cars.
Output
For each scenario, first print "Scenario x:" on a line by itself, where is the scenario number (starting from 1). On the next line, print the earliest arrival time of any vehicle at the crime intersection , as a floating point number rounded to two decimals. If no vehicle can reach the destination intersection, print "Impossible." instead. Separate two consecutive scenarios with a single blank line.