久久99热66热这里只有精品,特黄特色的大片在线观看,亚洲日本三级在线观看,国产三级农村妇女在线,亚洲av毛片免费在线观看,哺乳叫自慰在线看,天天干美女av网

poj1273 Drainage Ditches -電腦資料

電腦資料 時間:2019-01-01 我要投稿
【www.dameics.com - 電腦資料】

    Drainage DitchesTime Limit:1000MSMemory Limit:10000KTotal Submissions:64640Accepted:24923

    Description

Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.

    Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.

    Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

    Input

The input includes several cases.For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.

    Output

For each case, output a single integer, the maximum rate at which water may emptied from the pond.

    Sample Input

5 41 2 401 4 202 4 202 3 303 4 10

    Sample Output

50

    Source

USACO 93

    Dinic模板

#include<iostream>#include<cstdio>#include#include<cmath>#include<cstring>#include<queue>#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=k;i>=n;i--)#define LL long long#define pa pair<int,int>#define MAXN 205#define INF 1000000000using namespace std;int n,m,s,t,x,y,c,cnt=0,ans,dis[MAXN],cur[MAXN],head[MAXN];struct edge_type{	int next,to,v;}e[MAXN*2];inline int read(){	int x=0,f=1;char ch=getchar();	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}	return x*f;}inline void add_edge(int x,int y,int v){	e[++cnt]=(edge_type){head[x],y,v};head[x]=cnt;	e[++cnt]=(edge_type){head[y],x,0};head[y]=cnt;}inline bool bfs(){	queue<int>q;	memset(dis,-1,sizeof(dis));	dis[s]=0;q.push(s);	while (!q.empty())	{		int tmp=q.front();q.pop();		if (tmp==t) return true;		for(int i=head[tmp];i;i=e[i].next) if (e[i].v&&dis[e[i].to]==-1)		{			dis[e[i].to]=dis[tmp]+1;			q.push(e[i].to);		}	}	return false;}inline int dfs(int x,int f){	int tmp,sum=0;	if (x==t) return f;	for(int i=cur[x];i;i=e[i].next)	{		int y=e[i].to;		if (e[i].v&&dis[y]==dis[x]+1)		{			tmp=dfs(y,min(f-sum,e[i].v));			e[i].v-=tmp;e[i^1].v+=tmp;sum+=tmp;			if (e[i].v) cur[x]=i;			if (sum==f) return sum;		}	}	if (!sum) dis[x]=-1;	return sum;}inline void dinic(){	ans=0;	while (bfs())	{		F(i,s,t) cur[i]=head[i];		ans+=dfs(s,1<<30);	}	return;}int main(){	while (~scanf("%d",&m))	{		memset(head,0,sizeof(head));		n=read();		cnt=0;s=1;t=n;		F(i,1,m)		{			x=read();y=read();c=read();			add_edge(x,y,c);		}		dinic();		printf("%d\n",ans);	}}</int></int,int></queue></cstring></cmath></cstdio></iostream>

最新文章