#P1389G. Directing Edges
Directing Edges
Description
You are given an undirected connected graph consisting of vertices and edges. vertices of this graph are special.
You have to direct each edge of this graph or leave it undirected. If you leave the -th edge undirected, you pay coins, and if you direct it, you don't have to pay for it.
Let's call a vertex saturated if it is reachable from each special vertex along the edges of the graph (if an edge is undirected, it can be traversed in both directions). After you direct the edges of the graph (possibly leaving some of them undirected), you receive coins for each saturated vertex . Thus, your total profit can be calculated as , where is the set of saturated vertices, and is the set of edges you leave undirected.
For each vertex , calculate the maximum possible profit you can get if you have to make the vertex saturated.
The first line contains three integers , and (, , ).
The second line contains pairwise distinct integers , , ..., () — the indices of the special vertices.
The third line contains integers , , ..., ().
The fourth line contains integers , , ..., ().
Then lines follow, the -th line contains two integers and (, ) — the endpoints of the -th edge.
There is at most one edge between each pair of vertices.
Print integers, where the -th integer is the maximum profit you can get if you have to make the vertex saturated.
Input
The first line contains three integers , and (, , ).
The second line contains pairwise distinct integers , , ..., () — the indices of the special vertices.
The third line contains integers , , ..., ().
The fourth line contains integers , , ..., ().
Then lines follow, the -th line contains two integers and (, ) — the endpoints of the -th edge.
There is at most one edge between each pair of vertices.
Output
Print integers, where the -th integer is the maximum profit you can get if you have to make the vertex saturated.
Note
Consider the first example:
- the best way to make vertex saturated is to direct the edges as , ; is the only saturated vertex, so the answer is ;
- the best way to make vertex saturated is to leave the edge undirected and direct the other edge as ; and are the saturated vertices, and the cost to leave the edge undirected is , so the answer is ;
- the best way to make vertex saturated is to direct the edges as , ; is the only saturated vertex, so the answer is .
The best course of action in the second example is to direct the edges along the cycle: , , and . That way, all vertices are saturated.