POJ 1273
来源:互联网 发布:生产者消费者模式 php 编辑:程序博客网 时间:2024/04/19 14:30
#include <stdio.h>#include <string.h>int map[201][201], flag[201], queue[1000], pre[201], m, yes, min, searchmin[201];int find_min(int a, int b){ return a>b?b:a;}void bfs(){ memset(flag, 0, sizeof(flag)); int i, j, head, tail, x; searchmin[1]=100000; head=tail=0; queue[0]=1; yes=0; flag[1]=1; while(head<=tail) { x=queue[head]; for(i=1; i<=m; i++) if( (!flag[i]) && map[x][i]) { flag[i]=1; searchmin[i]=find_min(searchmin[x], map[x][i]); queue[++tail]=i; pre[i]=x; if(i==m) { yes=1; goto X; } } head++; } X: min=searchmin[m]; if(!yes) return; x=m; while(pre[x]) { map[ pre[x] ][x]-=min; map[x][pre[x]] += min; x=pre[x]; }} int main(){ int n, i, ans; pre[1]=0; while(scanf("%d%d", &n, &m)!=EOF) { ans=0; memset(map, 0, sizeof(map)); for(i=0; i<n; i++) { int x, y, xy; scanf("%d%d%d", &x, &y, &xy); map[x][y]+=xy; } while(1) { bfs(); if(!yes)break; else ans+=min; } printf("%d\n", ans); } return 0;}
虽然有些地方还是不太明白~~Orz
- POJ 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- POJ-1273
- poj-1273
- poj 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- Above the Clouds: A Berkeley View of Cloud
- CodeForce 78 Div2
- c++ 原来我一直没写对双目运算符函数
- 编程与生活
- sphinx 运行出现 error while loading shared libraries: libmysqlclient.so.16: cannot open shared object
- POJ 1273
- 2011.7.22
- Hibernate关联关系映射-----单向多对一映射配置
- 如何发表源代码帖
- 解决不能下载Xcode的办法
- TAOWEN的闲言碎语___Python完全新手教程
- 一个值得纪念的日子
- 24岁的程序员
- Data-Intensive Text Processing with MapReduce第三章(6)-MapReduce算法设计-3.5相关连接(RELATIONAL JOINS)