using System; namespace Ice { class Program { static int addFlow(int[,] c, int [,] f,bool[] visited,int n, int flow, int start){ visited[start]=true; int newFlow = 0; if(start == n-1){ visited[start]=false; return flow; } //forward: for(int j=0;jf[start,j]){ newFlow = Math.Min(flow,c[start,j]-f[start,j]); newFlow = addFlow(c,f,visited,n,newFlow, j); if(newFlow==0)continue; f[start,j]+= newFlow; visited[start]=false; return newFlow; } } //backward for(int i=0;i0){ newFlow = Math.Min(flow,f[i,start]); newFlow = addFlow(c,f,visited,n,newFlow, i); if(newFlow==0)continue; f[i,start]-= newFlow; visited[start]=false; return newFlow; } } visited[start]=false; return 0; } static int maxFlow(int[,] c, int[,] f, int n){ bool[] visited = new bool[n]; for(int i=0;i0){} int sum=0; for(int j=0;jf[start,j]){ printReachable(c,f,visited,n,columns,rows,j); } } //backward for(int i=0;i0){ printReachable(c,f,visited,n,columns,rows,i); } } } static void Main(){ int rows = Int32.Parse(Console.ReadLine()); int columns = Int32.Parse(Console.ReadLine()); int mode = Int32.Parse(Console.ReadLine()); int[,] d = new int[columns,rows]; for(int y =0;y