poj 1273 Drainage Ditches
来源:互联网 发布:北京户口重要吗 知乎 编辑:程序博客网 时间:2024/04/19 21:43
最大流入门题目
注意重边的处理
/*最大流问题*/
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int n,m;
int c[205][205];
int flow[205][205];
int a[205];
int pre[205];
const int inf = 0x7fffffff;
int maxFlow()
{
int ans = 0;
memset(flow,0,sizeof(flow));
queue<int>q;
while(1)
{
memset(a,0,sizeof(a));
a[1] = inf;
q.push(1);
while(!q.empty())
{
int temp = q.front();
q.pop();
for(int i = 1;i<=n;i++)
{
if(!a[i]&&c[temp][i]>flow[temp][i])
{
q.push(i);
pre[i] = temp;
if(c[temp][i]-flow[temp][i]<a[temp])
a[i] = c[temp][i]-flow[temp][i];
else
a[i] = a[temp];
}
}
}
if(a[n]==0)
break;
for(int i = n;i!=1;i=pre[i])
{
flow[pre[i]][i] += a[n];
flow[i][pre[i]] -= a[n];
}
ans += a[n];
}
return ans;
}
int main()
{
int u,v,w;
while(scanf("%d %d",&m,&n)!=EOF)
{
memset(c,0,sizeof(c));
for(int i=0;i<m;i++)
{
scanf("%d %d %d",&u,&v,&w);
c[u][v] += w;
}
int ans = maxFlow();
printf("%d\n",ans);
}
return 0;
}
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ-1273-Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- TCP和http
- Discuz 7.2漏洞入侵图解
- cent os 5.4 装git
- 移动互联网终端的touch事务,touchstart, touchend, touchmove
- 用JavaScript当用鼠标勾选一个CHECKBOX时,表格中对应的一行背景色变为黄色,文字字体变为红色粗体
- poj 1273 Drainage Ditches
- QT资源文件
- TP框架模型层简单的增删改查
- 12015 - Google is Feeling Lucky
- 初步学习KMP算法
- hdu 2135 Rolling table
- iOS ASIHTTPRequest详解
- JAVA和SQL2008
- 纯CSS3进度条制作-Pure CSS3 Progress Bar