#P3094. [USACO13DEC] Vacation Planning S

[USACO13DEC] Vacation Planning S

Description

There are NN farms numbered 1..N1..N with 1N2001 \le N \le 200. The airline plans to set up flight routes between the farms. Among these farms, those numbered 1..K1..K are designated as hub farms, where 1K1001 \le K \le 100 and KNK \le N.

There are currently MM directed flights (1M10,0001 \le M \le 10{,}000). Each flight goes from farm uiu_i to farm viv_i and costs did_i dollars, with 1di1,000,0001 \le d_i \le 1{,}000{,}000.

The airline has received QQ (1Q10,0001 \le Q \le 10{,}000) directed trip requests. The iith request is to travel from farm aia_i to farm bib_i. 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: NN, MM, KK, and QQ.
  • Lines 2..1+M2..1+M: Line i+1i+1 contains uiu_i, viv_i, and did_i for flight ii.
  • Lines 2+M..1+M+Q2+M..1+M+Q: Line 1+M+i1+M+i describes the iith trip in terms of aia_i and bib_i.

Output Format

  • Line 1: The number of trips (out of QQ) 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 1..31..3); farm 11 is a hub. There is a 10-dollar flight from farm 33 to farm 11, and so on. We wish to look for trips from 323 \to 2, from 232 \to 3, and from 121 \to 2.

The trip from 323 \to 2 has only one possible route, with cost 10+710+7. The trip from 232 \to 3 has no valid route, since there is no flight leaving farm 22. The trip from 121 \to 2 has only one valid route again, with cost 77.

Translated by ChatGPT 5