// 2 * InfL < long.MaxValue, and InfL is a prime number public static long CalcMaxFlow(int V, int source, int sink, List <GraphEdge> es) { var mes = new List <MFEdge> [V]; for (var u = 0; u < V; u++) { mes[u] = new List <MFEdge>(); } foreach (var e in es) { var e1 = new MFEdge(e.To, e.Capacity, null); var e2 = new MFEdge(e.From, 0, e1); e1.Reverse = e2; mes[e.From].Add(e1); mes[e.To].Add(e2); } return(MaxFlow(source, sink, mes)); }
public MFEdge(int to, long cap, MFEdge rev) { To = to; Capacity = cap; Reverse = rev; }