丑陋的代码……
[codec]
```cpp
//Ford-Fulkerson Algorithm
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxm 1000
#define maxn 1000
#define INF 10000005
using namespace std;
struct edge{
int to,cap,pre;
}e[2*maxm+1];
int h[maxn+1],n,m,top,s,t;
bool vis[maxn+1];
int addedge(int from,int to,int cap)
{
top++;
e[top].to=to;
e[top].cap=cap;
e[top].pre=h[from];
h[from]=top;
}
int dfs(int u,int t,int f)
{
if(u==t||f==0) return f;
vis[u]=true;
for(int i=h[u];i!=0;i=e[i].pre)
{
int v=e[i].to,d;
if(!vis[v]&&e[i].cap>0&&(d=dfs(v,t,min(e[i].cap,f)))>0)
{
e[i].cap-=d;
e[(i-1)^1+1].cap+=d;
return d;
}
}
return 0;
}
int get_num()
{
char c;
bool flag=false;
int num=0;
while((c=getchar())==' '||c=='\n'||c=='r');
if(c=='-') flag=true;
else num=c-'0';
while(isdigit(c=getchar())) num=num*10+c-'0';
return (flag?-1:1)*num;
}
int main()
{
m=get_num();
n=get_num();
top=0;
for(int i=1;i<=m;i++)
{
int u,v,c;
u=get_num();
v=get_num();
c=get_num();
addedge(u,v,c);
addedge(v,u,0);
}
//scanf("%d%d",&s,&t);
s=1;t=n;
int flow=0;
while(1)
{
memset(vis,false,sizeof(vis));
int f=dfs(s,t,INF);
if(f==0) break;
flow+=f;
}
printf("%d\n",flow);
return 0;
}
[\codec]
```
by Mys_C_K @ 2016-10-10 12:41:56
这个是FF??我感觉是EK呢
by Ghost_lzy @ 2016-10-20 00:01:13
我才发现这两个是一样的= =
by Ghost_lzy @ 2016-10-20 08:18:55
问题出在位运算(笑哭)
by Mys_C_K @ 2016-11-03 19:14:14
@[Ghost\_lzy](/space/show?uid=14410) FF是方法,EK是算法
by teafrogsf @ 2017-07-11 09:08:59
@[超神の曹](/space/show?uid=7020) Orz Orz
by yybyyb @ 2017-07-28 19:48:20