###### hdu 3987(最小割的边数)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 1<<30
#define maxn 1010
#define maxm 500000
using namespace std;

int v[maxm],Next[maxm],w[maxm];
int first[maxn],d[maxn],q[maxn];
int e,S,T;

void init(){
e = 0;
memset(first,-1,sizeof(first));
}

v[e] = b;Next[e] = first[a];w[e] = c;first[a] = e++;
v[e] = a;Next[e] = first[b];w[e] = 0;first[b] = e++;
}

int bfs(){
int rear = 0;
memset(d,-1,sizeof(d));
d[S] = 0;q[rear++] = S;
for(int i = 0;i < rear;i++){
for(int j = first[q[i]];j != -1;j = Next[j])
if(w[j] && d[v[j]] == -1){
d[v[j]] = d[q[i]] + 1;
q[rear++] = v[j];
if(v[j] == T)   return 1;
}
}
return 0;
}

int dfs(int cur,int maxflow){
if(cur == T)    return maxflow;
for(int i = first[cur];i != -1;i = Next[i]){
if(w[i] && d[v[i]] == d[cur] + 1)
if(int t = dfs(v[i],min(maxflow,w[i]))){
w[i] -= t;w[i^1] += t;
return t;
}
}
return 0;
}

int dinic(){
int ans = 0;
while(bfs()){
ans += dfs(S,INF);
}
return ans;
}

int main()
{
int n,m,ncase,cas = 1;
scanf("%d",&ncase);
while(ncase--)
{
init();
scanf("%d%d",&n,&m);
S = 0,T = n-1;
for(int i = 0;i < m;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
}
dinic();
for(int i = 0;i < e;i += 2){
if(w[i] == 0){
w[i] = 1;
w[i^1] = 0;
}else{
w[i] = INF;
w[i^1] = 0;
}
}
printf("Case %d: %d\n",cas++,dinic());
}
return 0;
}

#### hdu 3987(求割边最小的最小割）

2014-05-26 17:58:17

#### hdu 3987 最小割

2014-01-25 12:59:47

#### HDU 3987 Harry Potter and the Forbidden Forest（最小割中的最少割边）经典

2015-08-02 21:04:49

#### hdu 3987 求最小割条数最小

2014-12-01 21:50:55

#### hdu 3987 Harry Potter and the Forbidden Forest

2017-04-19 19:49:12

#### hdu 3987 求割边最少的最小割

2016-07-25 13:45:23

#### hdu 3657 最小割（牛逼！！！！）总算理解了,必看！！！！！！！！！！！！！

2014-10-21 17:41:32

#### hdu3251 最小割

2016-07-25 18:42:36

#### 最小割模型（hdu5076 2014鞍山）

2015-05-17 19:59:15

#### Being a Hero (hdu 3251 最小割 好题)

2015-07-26 16:51:40

hdu 3987(最小割的边数)