PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000078. Chi phí đường đi và tiệc (Asterix and Obelix)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chi phí đường đi và tiệc (Asterix and Obelix)
Asterix and Obelix
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Every undirected road has a travel cost and every city has a feast cost. An itinerary costs the sum of its road costs plus the maximum feast cost over all visited cities, including its endpoints. Answer minimum-cost queries.
Input
First ; then feast costs, undirected roads , and queries , all 1-based.
Output
For each query print the minimum cost or -1 if disconnected.
Subtasks
-
Subtask 1 (40 points): . , ; .
-
Subtask 2 (60 points): . , ; .
Examples
Input
3 2 3
5 10 20
1 2 2
2 3 3
1 3
1 2
3 3
Output
25
12
20
Explanation
The route 1–2–3 costs 5 in road expenses and has a maximum feast cost of 20, totaling 25. The route 1–2 costs 12; staying at 3 costs its feast fee of 20.