Alternative Mart
Time limit5sMemory limit512 MB
For each query, find the closest open discount mart from start region S, skipping up to 10 closed marts, and print its number and the shortest distance.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph, Heap
- Solved
- No attempts yet
Problem
Minsik lives alone in OJUZ City. OJUZ City has regions and bidirectional roads, and of the regions have a discount mart. Region numbers are integers from 1 to . At most one road directly connects any two regions, and the two endpoints of every road are different. Any region can reach any other region.
When his work ends, Minsik goes to a discount mart to buy cooking ingredients and snacks, then returns to his apartment. He always takes the fastest route to a discount mart. Sometimes some marts are closed. When a mart is closed, the route he used before may no longer work.
Write a program that finds, for each query, which discount mart Minsik should go to. Ignore the time needed to travel from the mart back home.
Input
The first line contains , , , and , the number of regions, roads, discount marts, and queries. (, , , )
The second line contains the region numbers with discount marts, in ascending order.
Each of the next lines contains two endpoints , and the length of a road. (, )
Each of the next lines is a query: a start region , the number of closed marts , and the region numbers of the closed marts. (, )
Output
For each query, print the number of the discount mart Minsik should visit (the region where it is located) and the minimum time to get there. If several marts tie for the shortest time, print the smallest number.