docca0 @ 2020-07-27 10:42:02
我用FF算法过了另一道模板题P2740,但是为啥这道题就10个re??
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#define maxn 205
#define inf 0x3f3f3f3f
using namespace std;
struct edge{
int to,cap,rev;
edge(int _to,int _cap,int _rev){
to=_to;
cap=_cap;
rev=_rev;
}
};
vector<edge> G[maxn];
bool used[maxn];
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 v,int t,int f){
if(v==t)return f;
used[v]=1;
for(int i=0;i<G[v].size();i++){
edge&e=G[v][i];
if(!used[e.to]&&e.cap>0){
int d=dfs(e.to,t,min(e.cap,f));
if(d>0){
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
}
}
int max_flow(int s,int t){
int flow=0;
while (true)
{
memset(used,0,sizeof(used));
int f=dfs(s,t,inf);
if(f==0)return flow;
flow+=f;
}
}
int main()
{
int n,m,s,t;
scanf("%d%d%d%d",&n,&m,&s,&t);
for(int i=0;i<m;i++){
int a,b,w;
scanf("%d%d%d",&a,&b,&w);
add_edge(a,b,w);
}
printf("%d\n",max_flow(s,t));
return 0;
}
by JiangShenli @ 2020-08-01 16:46:48
如果我学的时候没有学错的话,ff是没有准确的复杂度的,所以能不能跑完全看rp
by JiangShenli @ 2020-08-01 16:47:16
EK也是慢的,建议dinic
by JiangShenli @ 2020-08-01 16:55:53
这题EK是能a的,但是赛场上一般dinic