ZOJ Problem Set - 2429
Alice and Bob play the following game. First, Alice draws some directed graph with N vertices and M arcs. After that Bob tries to destroy it. In a move he may take any vertex of the graph and remove either all arcs incoming into this vertex, or all arcs outgoing from this vertex.
Alice assigns two costs to each vertex: Wi+ and Wi-. If Bob removes all arcs
Find out what minimal sum Bob needs to remove all arcs from the graph.
Input describes the graph Alice has drawn. The first line of the input contains N and M (1 <= N <= 100, 1 <= M <= 5000). The second line contains N integer numbers specifying Wi+. The third line defines Wi- in a similar way. All costs are positive and do not exceed 10^6. Each of the following M lines contains two integers describing the corresponding arc of the graph. Graph may contain loops and parallel arcs.
On the first line of the output file print W - the minimal sum Bob must have to remove all arcs from the graph. On the second line print K - the number of moves Bob needs to do it. After that print K lines that describe Bob's moves. Each line must first contain the number of the vertex and then '+' or '-' character, separated by one space. Character '+' means that Bob removes all arcs incoming into the specified vertex and '-' that Bob removes all arcs outgoing from the specified vertex.
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between
Source: Northeastern Europe 2003, Northern Subregion