using System.Collections.Generic;
static readonly int V = 6;
bool bfs(int[, ] rGraph, int s, int t, int[] parent)
bool[] visited = new bool[V];
for (int i = 0; i < V; ++i)
List<int> queue = new List<int>();
while (queue.Count != 0) {
for (int v = 0; v < V; v++) {
int fordFulkerson(int[, ] graph, int s, int t)
int[, ] rGraph = new int[V, V];
rGraph[u, v] = graph[u, v];
int[] parent = new int[V];
while (bfs(rGraph, s, t, parent)) {
int path_flow = int.MaxValue;
for (v = t; v != s; v = parent[v]) {
= Math.Min(path_flow, rGraph[u, v]);
for (v = t; v != s; v = parent[v]) {
rGraph[u, v] -= path_flow;
rGraph[v, u] += path_flow;
public static void Main()
int[, ] graph = new int[, ] {
{ 0, 16, 13, 0, 0, 0 }, { 0, 0, 10, 12, 0, 0 },
{ 0, 4, 0, 0, 14, 0 }, { 0, 0, 9, 0, 0, 20 },
{ 0, 0, 0, 7, 0, 4 }, { 0, 0, 0, 0, 0, 0 }
MaxFlow m = new MaxFlow();
Console.WriteLine("The maximum possible flow is "
+ m.fordFulkerson(graph, 0, 5));