#P3096. [USACO13DEC] Vacation Planning G

[USACO13DEC] Vacation Planning G

Description

Air Bovinia operates flights connecting the NN farms that the cows live on (1N20,0001 \le N \le 20{,}000). As with any airline, KK of these farms have been designated as hubs (1K2001 \le K \le 200, KNK \le N).

Currently, Air Bovinia offers MM one-way flights (1M20,0001 \le M \le 20{,}000), where flight ii travels from farm uiu_i to farm viv_i and costs did_i dollars (1di10,0001 \le d_i \le 10{,}000). As with any other sensible airline, for each of these flights, at least one of uiu_i and viv_i is a hub. There is at most one direct flight between two farms in any given direction, and no flight starts and ends at the same farm.

Bessie is in charge of running the ticketing services for Air Bovinia. Unfortunately, while she was away chewing on delicious hay for a few hours, QQ one-way travel requests for the cows' holiday vacations were received (1Q50,0001 \le Q \le 50{,}000), where the iith request is from farm aia_i to farm bib_i.

As Bessie is overwhelmed with the task of processing these tickets, please help her compute whether each ticket request can be fulfilled, and its minimum cost if it can be done.

To reduce the output size, you should only output the total number of ticket requests that are possible, and the minimum total cost for them. Note that this number might not fit into a 3232-bit integer.

In other words, given a directed graph with NN nodes and MM edges, for each query find the shortest path whose route must pass through at least one node with an index in 1..K1..K.

Input Format

  • Line 11: The integers NN, MM, KK, and QQ.
  • Lines 2..M+12..M+1: Line i+1i+1 contains uiu_i, viv_i, and did_i. (1ui,viN1 \le u_i, v_i \le N, uiviu_i \ne v_i.)
  • Lines M+2..M+K+1M+2..M+K+1: Each of these lines contains the ID of a single hub (in the range 1..N1..N).
  • Lines M+K+2..M+K+Q+1M+K+2..M+K+Q+1: Two numbers per line, indicating a request for a ticket from farm aia_i to bib_i. (1ai,biN1 \le a_i, b_i \le N, aibia_i \ne b_i.)

Output Format

  • Line 11: The number of ticket requests that can be fulfilled.
  • Line 22: The minimum total cost of fulfilling the possible ticket requests.
3 3 1 2 
1 2 10 
2 3 10 
2 1 5 
2 
1 3 
3 1 

1 
20 

Hint

For the first flight, the only feasible route is 1231 \to 2 \to 3, costing 2020. There are no flights leaving farm 33, so the poor cows are stranded there.

Translated by ChatGPT 5