#include #include #include #include #include #include #include #include #include #include using namespace std; struct edge{ int to; int cap; int rev; bool is_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(), false} ); G[to].push_back( (edge){from, 0, (int)G[from].size()-1, true} ); } int main(){ int N; cin >> N; vector A(N); for(int i=0; i> A[i]; } vector> G(2*N+2); int s = 2*N; int t = 2*N+1; for(int i=0; i