Vacation Planning
Time limit3sMemory limit256 MB
Given a flight network where every edge touches one of K hubs, count how many of Q trip requests are reachable and sum their cheapest costs.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
Air Bovinia runs flights between the farms where the cows live (). of those farms are hubs (, ).
The airline currently offers one way flights (). Flight goes from farm to farm and costs dollars (). On every flight at least one of and is a hub. Two farms have at most one direct flight in a given direction, and no flight starts and ends at the same farm.
Bessie runs the ticket desk for Air Bovinia. While she was away chewing delicious hay for a few hours, one way travel requests for the holiday vacations arrived (). Request asks for a ticket from farm to farm .
Decide for each request whether it can be fulfilled, and find its minimum cost when it can.
To keep the output small, print only how many requests can be fulfilled and the minimum total cost of fulfilling those requests. That total may not fit in a 32 bit integer.
Input
- Line 1: the integers , , , and .
- Lines 2 to : , , and . (, )
- Lines to : each line holds the ID of one hub, between and .
- Lines to : two numbers per line, a ticket request from farm to farm . (, )
Output
- Line 1: the number of ticket requests that can be fulfilled.
- Line 2: the minimum total cost of fulfilling those requests.
Hint
In the example the first request can only travel farm 1 → 2 → 3 at a cost of 20. No flight leaves farm 3, so the second request cannot be fulfilled.