#P3094. [USACO13DEC] Vacation Planning S
[USACO13DEC] Vacation Planning S
Description
There are farms numbered with . The airline plans to set up flight routes between the farms. Among these farms, those numbered are designated as hub farms, where and .
There are currently directed flights (). Each flight goes from farm to farm and costs dollars, with .
The airline has received () directed trip requests. The th request is to travel from farm to farm . A valid trip must pass through at least one hub farm (it may be the starting or ending farm). The route may visit the same farm multiple times.
Compute the number of trip requests for which a valid route exists, and the total cost to complete all valid requests, where each valid request is taken with its minimum possible route cost.
Input Format
- Line 1: Four integers: , , , and .
- Lines : Line contains , , and for flight .
- Lines : Line describes the th trip in terms of and .
Output Format
- Line 1: The number of trips (out of ) for which a valid route is possible.
- Line 2: The sum, over all trips for which a valid route is possible, of the minimum possible route cost.
3 3 1 3
3 1 10
1 3 10
1 2 7
3 2
2 3
1 2
2
24
Hint
There are three farms (numbered ); farm is a hub. There is a 10-dollar flight from farm to farm , and so on. We wish to look for trips from , from , and from .
The trip from has only one possible route, with cost . The trip from has no valid route, since there is no flight leaving farm . The trip from has only one valid route again, with cost .
Translated by ChatGPT 5
京公网安备 11011102002149号