poj 1273 Drainage Ditches
来源:互联网 发布:js timer控件 编辑:程序博客网 时间:2024/04/19 07:59
也是一道模板题目...敲一遍熟悉熟悉
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <vector>#include <set>#include <queue>#include <stack>#include <climits>//形如INT_MAX一类的#define MAX 205#define INF 0x7FFFFFFF# define eps 1e-5//#pragma comment(linker, "/STACK:36777216") ///传说中的外挂using namespace std;int cap[MAX][MAX],pre[MAX],flow[MAX];int m,n;int bfs(int s,int e){ queue<int >q; memset(pre,-1,sizeof(pre)); pre[s] = 0; flow[s] = INF; q.push(s); while(! q.empty()) { int t = q.front(); q.pop(); if(t == e) break; for(int i=1; i<=m; i++) { if(pre[i] == -1 && cap[t][i] > 0 ) { q.push(i); pre[i] = t; flow[i] = min(flow[t],cap[t][i]); } } } if(pre[e] == -1) return -1; return flow[e];}int maxflow(int s,int e){ int imp=0; int sum=0; while((imp = bfs(s,e)) != -1) { int ind = e; while(ind != s) { cap[pre[ind]][ind] -= imp; cap[ind][pre[ind]] += imp; ind = pre[ind]; } sum += imp; } return sum;}void init(){ memset(cap,0,sizeof(cap)); memset(flow,0,sizeof(flow));}int main(){ int a,b,c; while(scanf("%d%d",&n,&m) != EOF) { init(); for(int i=0; i<n; i++) { scanf("%d%d%d",&a,&b,&c); if(a == b) continue; cap[a][b] += c; } printf("%d\n",maxflow(1,m)); } 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
- 连接词识别
- 【java工具类】对velocity的封装
- 彻底明白红黑树
- 如何做一名优秀的博士生:(一)时间的付出 施一公
- 一天的收获
- poj 1273 Drainage Ditches
- PyQt4学习资料
- 接口和抽象类异同
- 网站安全检测:推荐8款免费的 Web 安全测试工具
- 红黑树插入和删除结点的全程演示
- ORACLE常见问题
- Android错误异常收集
- 【销毁窗口】关键消息和方法
- 一道经典多线程题