Destroying the Graph
Time limit1sMemory limit512 MB
Find the minimum cost to cover every arc of a directed graph by choosing, for each vertex, to delete its incoming or outgoing arcs.
- Level
Hard8 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Sorting
- Solved
- No attempts yet
Problem
Alice and Bob play the following game. First, Alice draws a directed graph with vertices and arcs. Then Bob tries to destroy it by removing every arc. In one move Bob picks any vertex and removes either all arcs coming into that vertex or all arcs going out of that vertex.
Alice assigns two costs to each vertex : and . If Bob removes all arcs incoming into vertex he pays Alice dollars, and if he removes all arcs outgoing from vertex he pays dollars. Determine the minimum total amount Bob must pay to remove all arcs from the graph.
Input
The first line contains two integers and (, ). The second line contains integers . The third line contains in the same way. All costs are positive integers not exceeding . Each of the following lines contains two integers and , describing an arc from vertex to vertex . The graph may contain loops and parallel arcs.
Output
Print a single integer — the minimum total amount Bob must pay to remove all arcs from the graph.