UVa 11506 - Angry Programmer

11506 - Angry Programmer

 * https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2501

Summary
Given a simple undirected graph with N (<=50) vertices. Each vertex (except vertex #1 and vertex #N) can be removed with a cost. Similarly, each edge can be removed with a cost. You want to make vertex #1 to be disjoint with vertex #N by removing some vertices or edges and you want to do it with minimal total cost.

Explanation
A slight modification to the graph can reduce this problem into the minimum-cut problem, which is the dual of the maximum-flow problem. That is by splitting each vertex into two vertices and connect them with an edge with a removal cost equal to the vertex's removal cost.

Gotchas

 * The flow graph has to be directed.

Implementations
A simple implementation based on Ford-Fulkerson method to find the maximum-flow of the graph can be used to find the minimum-cut of the graph.

Optimizations
Storing the flow network using adjacency list can be faster, however it is slightly harder to implement.