題目:
鏈接:點擊打開鏈接
題意:
求最大流速。
思路:
Edmond_karp就行。
代碼:
#include#include #include #include using namespace std; #define INF 100000000 const int N = 220; int cap[N][N],flow[N][N]; int a[N]; int n,m; int s,e,c; void edmonds_karp(int s,int t) { queue q; memset(flow,0,sizeof(flow)); int f = 0; int p[N]; for(;;) { memset(a,0,sizeof(a)); a[s] = INF; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v=1; v<=n; v++) { if(!a[v] && cap[u][v] > flow[u][v]) { p[v] = u; q.push(v); a[v] = a[u] < cap[u][v] - flow[u][v] ? a[u] : cap[u][v] - flow[u][v]; } } } if(a[t] == 0) break; for(int u=t; u!=s; u=p[u]) { flow[p[u]][u] += a[t]; flow[u][p[u]] += a[t]; } f += a[t]; } printf("%d\n",f); } int main() { //freopen("input.txt","r",stdin); while(scanf("%d%d",&n,&m) != EOF) { memset(cap,0,sizeof(cap)); for(int i=0; i -------------------------------------------------------------------------------- 收獲:
------>增廣路算法,Edmond_karp模板:
queueq; memset(flow,0,sizeof(flow)); int f = 0; int p[N]; for(;;) { memset(a,0,sizeof(a)); a[s] = INF; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v=1; v<=n; v++) { if(!a[v] && cap[u][v] > flow[u][v]) { p[v] = u; q.push(v); a[v] = a[u] < cap[u][v] - flow[u][v] ? a[u] : cap[u][v] - flow[u][v]; } } } if(a[t] == 0) break; for(int u=t; u!=s; u=p[u]) { flow[p[u]][u] += a[t]; flow[u][p[u]] += a[t]; } f += a[t]; }
------------------------------------------------------------------戰斗,從不退縮;奮斗,永不停歇~~~~~~~~~~~~~