#include <iostream>
#include <vector>
#include <cstring>
#define INF 0xfffff
#define MAXV 100
using namespace std;
struct edge {
int to; //终点
int cap; //容量
int rev; //反向边
};
vector<edge> G[MAXV]; //图的邻接表
bool used[MAXV]; //DFS中用到的访问标记
void add_edge(int from, int to, int cap) {
G[from].push_back((edge){to, cap, G[to].size()}); //正向边
G[to].push_back((edge){from, 0, G[from].size() - 1}); //反向边
}
int dfs(int s, int t, int f) {
if(s == t)
return f;
used[s] = true;
for(int i = 0; i < G[s].size(); ++i) {
edge &e = G[s][i];
if(!used[e.to] && e.cap > 0) {
int d = dfs(e.to, t, min(f, e.cap));
if(d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int max_flow(int s, int t) { //s为源点,t为汇点
int flow = 0;
for(;;) {
memset(used, 0, sizeof(used));
int f = dfs(s, t, INF);
if(f == 0)
return flow;
flow += f;
}
}
08-16
08-16