#include #include #include #include #include #include #include #include #include using namespace std; struct edge{ int to; int cap; int rev; }; int Ford_Fulkerson_dfs(vector > &G, int pos, int flow, vector &used, int t){ if(pos == t){ return flow; }else{ used[pos] = true; for(int i=0; i0){ int myflow = Ford_Fulkerson_dfs(G, G[pos][i].to, min(flow, G[pos][i].cap), used, t); if(myflow > 0){ G[pos][i].cap -= myflow; G[ G[pos][i].to ][ G[pos][i].rev ].cap += myflow; return myflow; } } } return 0; } } int Ford_Fulkerson(vector > &G, int s, int t){ const int INF = 100000000; int flow=0; for(;;){ vector used(G.size(), false); int f = Ford_Fulkerson_dfs(G, s, INF, used, t); if(f==0) break; else flow += f; } return flow; } void add_edge(vector > &G, int from, int to, int cap){ G[from].push_back( (edge){to, cap, (int)G[to].size()} ); G[to].push_back( (edge){from, 0, (int)G[from].size()-1} ); } int main(){ int n,m; cin >> n >> m; vector v(n); for(int i=0; i> v[i]; } // s -> w -> b -> t vector< vector > G(n*m + 2); int s = n*m; int t = n*m+1; int cnt_w = 0; int cnt_b = 0; for(int i=0; i