最大流dinic模板

2021-07-04 11:16:33 字數 1218 閱讀 1683

運輸問題1

★★☆ 輸入檔案:maxflowa.in 輸出檔案:maxflowa.out 簡單對比

時間限制:1 s 記憶體限制:128 mb

【問題描述】

乙個工廠每天生產若干商品,需運輸到銷售部門進行銷售。從產地到銷地要經過某些城鎮,有不同的路線可以行走,每條兩城鎮間的公路都有一定的流量限制。請你計算,在不考慮其它車輛使用公路的前提下,如何充分利用所有的公路,使產地運輸到銷地的商品最多,最多能運輸多少商品。

【輸入格式】

輸入檔案有若干行

第一行,乙個整數n,表示共有n個城市(2<=n<=100),產地是1號城市,銷地是n號城市。

下面有n行,每行有n個數字。第p行第q列的數字表示城鎮p與城鎮q之間有無公路連線。數字為0表示無,大於0表示有公路,且該數字表示該公路流量。

【輸出格式】

輸出檔案有一行

第一行,1個整數max,表示最大流量為max。

【輸入輸出樣例】

輸入檔名: maxflowa.in

6 0 4 8 0 0 0

0 0 4 4 1 0

0 0 0 2 2 0

0 0 0 0 0 7

0 0 0 6 0 9

0 0 0 0 0 0

輸出檔名:maxflowa.out

8

#include

#include

#include

using namespace std;

const int maxn=1010,inf=0x7fffffff/3;

int n,s,x,tot=1,ans=0;

struct edgeg[maxn*10];

int h[maxn],q[maxn*10],cur[maxn],vis[maxn];

void add(int

x,int

y,int z)

bool bfs()

}return vis[n]!=-1;

}int dfs(int

x,int f)

if (!used) vis[x]=-1;

return used;

}void dinic()return;

}int main()

}dinic();

printf("%d",ans);

return

0;}

最大流 Dinic模板

date 2015 8 21 晚上 author itak motto 今日的我要超越昨日的我,明日的我要勝過今日的我 以創作出更好的 為目標,不斷地超越自己。include include using namespace std oo表示無窮大 const int oo 1e9 5 mm表示邊的最...

最大流模板(Dinic)

和最小費用流模板對比著看 最小費用流模板 貼上最大流模板 include includeusing namespace std const int oo 1e9 oo 表示無窮大 const int mm 111111111 mm 表示邊的最大數量,記住要是原圖的兩倍,在加邊的時候都是雙向的 con...

最大流dinic模板

include include include include define inf 0x3f3f3f3f3f3f3f3f define ll long long define maxn 10005 using namespace std int n,m 點數 邊數 int sp,tp 原點 匯點 ...