hdu1532

/*
分析:
    网络流果题~~~
    秉承绝不抄袭、自己debug的原则,经过两个月的努力,终于
于今天这个值得纪念的日子里,检查出了那一~个小bug,ac掉了
俺第一个网络流。(我是该高兴还是该桑心~-、-III)
    泪奔~~~(可以安心吃午饭上体育课去了@。@。。。)

                               2012-10-09  15:23
*/








#include"stdio.h"  
#include"string.h"  
#include"queue"  
using namespace std;  
int v,e;  
int flow[211][211];  
int rest[211][211];  
int pre[211],hash[211];  

struct node  
{  
    int dot;  
};  
int min(int a,int b)  
{  
    return a>b?b:a;  
}
int BFS()  
{  
    queue<node>q;  
    node now,next;  
    int i;  

    memset(pre,-1,sizeof(pre));  
    memset(hash,0,sizeof(hash));
    now.dot=1;  
    hash[1]=1;
    q.push(now);  

    while(!q.empty())  
    {  
        now=q.front();  
        q.pop();  
        if(now.dot==v)  return 1;  
        for(i=1;i<=v;i++)  
        {
			if(!hash[i] && rest[now.dot][i])
			{
				pre[i]=now.dot;
				hash[i]=1;
				next.dot=i;
				q.push(next);
			}
        }
    }  
    return 0;  
}  
int update()  
{  
    int t,p;  

    p=111111111;
    t=v;
	while(t!=1)  
    {
		p=min(p,rest[pre[t]][t]);
        t=pre[t];  
    }  
    t=v;  
    while(t!=1)  
    {
		rest[pre[t]][t]-=p;
		rest[t][pre[t]]+=p;
        t=pre[t];  
    }
    return p;  
}  
int main()  
{  
    int a,b,c;  
    __int64 ans;  
    while(scanf("%d%d",&e,&v)!=-1)  
    {  
        memset(flow,0,sizeof(flow));  
        memset(rest,0,sizeof(rest));  
        while(e--)  
        {  
            scanf("%d%d%d",&a,&b,&c);  
			rest[a][b]+=c;
        }  
  
        ans=0;  
        while(BFS())    ans+=update();  
        printf("%I64d\n",ans);  
    }  
    return 0;  
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值