using System; using System.Collections.Generic; namespace Ice { class Program{ class Edge{ public int node; public int id; public Edge(int node, int id){ this.node = node; this.id = id; } } struct Graph{ public int am_nodes; public List[] nodes; public Graph(int am_nodes){ this.am_nodes = am_nodes; nodes = new List[am_nodes]; for(int i=0;i(); } } } //This was necessary, because tuples are not allowed struct GraphWeights{ public Graph g; public int[] w; } //This was necessary, because tuples are not allowed struct EdgeNode{ public Edge e; public int n; } //This was necessary, because tuples are not allowed struct GraphWeightsFlow{ public GraphWeights gw; public int flow; } static void BFS(bool[] visited,Graph g,int[] w,EdgeNode[] parent,int s,int t){ visited[s] = true; //s has no parent parent[s].n = -1; parent[t].n = -1; Queue queue = new Queue(); queue.Enqueue(s); while(queue.Count!=0){ int u = queue.Dequeue(); foreach(Edge e in g.nodes[u]){ int v = e.node; if(w[e.id]>0&&!visited[v]){ parent[v].e=e; parent[v].n=u; if(v==t)return; visited[v] = true; queue.Enqueue(v); } } } } static void DFS(bool[] visited,Graph g,int[] w,int a){ visited[a] = true; foreach(Edge e in g.nodes[a]){ if(w[e.id]>0&&!visited[e.node]){ DFS(visited, g,w, e.node); } } } static GraphWeights residualGraph(Graph G, int[] c, int[] f){ int am_edges = c.Length; //The weights of the residualGraph int[] c_f =new int[2*am_edges]; Graph G_f = new Graph(G.am_nodes); for(int i=0;i c = new List(); int id =0; for(int x=0;x