Cheeseburger
InterviewTime limit1sMemory limit1024 MB
Each farm supplies only the chain stores nearest to it, and each store pays the cheapest price among farms that can supply it. Output that price per store, or -1.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
Jeonghu rides the subway often. The subway map has stations connected by rail lines. The -th rail line connects stations and in both directions, and travel between those two stations takes time.
One day, Jeonghu ate a cheeseburger at a subway station and came to love cheeseburgers so much that he opened cheeseburger chain stores at stations . All that remains is to transport the cheese.
Jeonghu found cheese farms near stations . The cheese at the farm near station costs . Jeonghu delivers cheese to each chain store by KTX express, and a KTX express delivery takes the same time as travel between stations.
Each farm can supply cheese to every chain store that has the shortest delivery time from that farm, where the shortest delivery time is taken over one or more chain stores. Each chain store buys the cheapest cheese it can be supplied with. What price does each chain store pay?
Input
The first line contains four integers , , , and , separated by spaces.
The second line contains integers , separated by spaces.
The next lines each contain two integers and , separated by a space.
The next lines each contain three integers , , and , separated by spaces.
Output
Print integers on one line, separated by spaces, where the -th integer is the price of the cheese that the -th chain store buys. If a chain store cannot buy any cheese, print -1 for it.
Constraints
- If , then and