#P10129. Urban Planning Rescue
Urban Planning Rescue
Urban Planning Rescue
The Provence-Alpes-Côte d'Azur region is in trouble! The regional managers need your help to solve a city planning problem.
There are (t) managers and (n) cities. In the (i)-th city, there are (k_i) villages, numbered from (1) to (k_i). Inside each city, there are (p_i) roads. Each road (j) in city (i) connects village (u_{i,j}) and village (v_{i,j}) (with (1 \le u_{i,j},v_{i,j} \le k_i)) and is managed by manager (w_{i,j}) with a passenger flow of (z_{i,j}). It is guaranteed that each manager manages at most one road in a single city.
Due to disaster, all these roads are damaged. To restore traffic within each city, you must choose an integer parameter (c_i) for each city (i) with (1 \le c_i \le k_i). In city (i), villages (1) through (c_i) will be repaired and a road will be automatically restored if both its endpoints (villages) are repaired. However, repairing villages comes with a cost: repairing the first (c_i) villages in city (i) costs (b_{i,c_i}).
Inter-city there are (m) high-speed rails. Each rail connects two cities (u) and (v), and the (n) cities along with these rails form a bipartite graph. For the sake of team unity, a manager will only be happy if, for every pair of his roads that are located in two different cities directly connected by a high-speed rail, at least one of the roads is restored. Otherwise, for every such pair of unrepaired roads (say with passenger flows (z_1) and (z_2)), you must pay a penalty of (z_1\times z_2). Note that if a manager has more than two unrepaired roads in cities connected by high-speed rails, the penalty is computed for every pair.
Your task is to determine the minimum total cost (restoration cost plus penalty costs) needed so that all managers are happy and the requirements (1 \le c_i \le k_i) are met for every city (i).
Important: All formulas are given in (\LaTeX) format.
inputFormat
The input begins with two integers (t) and (n) on the first line. Then for each city (i) (from (1) to (n)) there is a block of input as follows:
• A line containing two integers: (k_i) (number of villages) and (p_i) (number of roads in the city).
• A line with (k_i) integers: (b_{i,1}, b_{i,2}, \ldots, b_{i,k_i}), where (b_{i,c_i}) is the cost to repair villages (1) to (c_i) in city (i).
• Then (p_i) lines follow, each containing four integers: (u_{i,j}), (v_{i,j}), (w_{i,j}), and (z_{i,j}), describing a road between villages (u_{i,j}) and (v_{i,j}) that is managed by manager (w_{i,j}) with passenger flow (z_{i,j}).
After the cities, there is a line containing an integer (m) (the number of high-speed rails), followed by (m) lines, each with two integers (u) and (v) representing a rail connecting city (u) and city (v).
outputFormat
Output a single integer: the minimum total cost required.
sample
2 2
2 1
5 10
1 2 1 3
2 1
4 9
1 2 1 2
1
1 2
14