Under construction

Still being built. Things may change

Emergency Response

Time limit1sMemory limit128 MB

Summary
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 nn intersections and mm roads. Each road is given by its starting intersection ii, its ending intersection jj, and the travel time t(i,j)≥0t(i,j) \ge 0. If a pair (i,j)(i,j) does not appear in the list, there is no direct road from ii to jj. Roads are directed, so the time from ii to jj need not equal the time from jj to ii (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 n,m,sn, m, s. n≤1000n \le 1000 is the number of intersections, m≤10000m \le 10000 is the number of roads, and ss is the number of scenarios that follow. This is followed by mm lines, each describing one road with three numbers: the starting intersection ii, the ending intersection jj, and the travel time t(i,j)≥0t(i,j) \ge 0 (a floating point number).

Then come ss scenarios. The first line of each scenario contains two numbers c,kc, k. cc is the intersection at which the crime happened and kk is the number of cars dispatched. The next line contains kk numbers separated by single spaces: the starting intersections of the kk cars.

Output

For each scenario, first print "Scenario x:" on a line by itself, where xx is the scenario number (starting from 1). On the next line, print the earliest arrival time of any vehicle at the crime intersection cc, 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.

Examples3

  1. Example 1

    Input
    6 9 2
    1 2 3.5
    1 3 1.2
    3 4 4.9
    2 4 0.221
    5 4 0.1
    5 6 1.3
    4 6 1
    2 3 0
    3 2 5
    4 2
    1 3
    5 1
    6
    
    Expected output
    Scenario 1:
    3.72
    
    Scenario 2:
    Impossible.
    
  2. Example 2

    Input
    3 3 1
    1 2 1.0
    2 3 2.0
    1 3 10.0
    3 2
    1 2
    
    Expected output
    Scenario 1:
    2.00
    
  3. Example 3

    Input
    2 1 1
    1 2 3.5
    1 1
    1
    
    Expected output
    Scenario 1:
    0.00