Power Grid
Shichikuji must supply electricity to n cities. City i sits at coordinates (xi,yi).
A city has electricity if it has a power station, or if it is connected (directly or through other cities) to a city that does.
- Building a power station in city i costs ci.
- Connecting cities i and j with a wire costs (ki+kj)⋅(∣xi−xj∣+∣yi−yj∣).
Wires run along cardinal directions, so their length is the Manhattan distance between the two cities. Find the minimum cost to give every city electricity.
Input
The first line contains an integer n.
The next n lines each contain two integers xi and yi.
The next line contains n integers c1,c2,…,cn.
The last line contains n integers k1,k2,…,kn.
Output
Output a single integer: the minimum cost.
Constraints
- 1≤n≤2000
- 1≤xi,yi≤106
- 1≤ci,ki≤109
Example 1
3
2 3
1 1
3 2
3 2 3
3 2 3
8
Explanation
Building a station in every city costs 3+2+3=8, which is optimal.
Example 2
3
2 1
1 2
3 3
23 2 23
3 2 3
27
Explanation
Build a station in city 2 (cost 2), connect 1--2 (cost 10), and connect 2--3 (cost 15), for a total of 27.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.