USACO 4.2.1 PROB Drainage Ditches
来源:互联网 发布:mac 迅雷 编辑:程序博客网 时间:2024/06/01 16:55
标准网络流
注意:
1、这个题中,流单向
2、环可以不考虑
3、如果有多条 u-->v,直接相加就可以
/*ID : lancelo2PROG : ditchLANG : C++*/ #include <fstream>#include <iostream>#include <algorithm>#include <queue>#include <cstring>#define INT_MAX 100000000using namespace std;const int MAXN = 200;int n, p[MAXN+1], map[MAXN+1][MAXN+1];int N, M;bool ek_bfs(int s, int e){queue<int> q;bool flag[MAXN+1];memset(flag, 0, sizeof(flag));memset(p, -1, sizeof(p));q.push(s);flag[s] = true;while(!q.empty()){int n = q.front();if(n == e)return true;q.pop();for(int i = 1; i <= e; i++){if(map[n][i] > 0 && !flag[i]){flag[i] = true;p[i] = n;q.push(i);}}}return false;}int ek(int s, int e){int u, flow_ans = 0, mn;while(ek_bfs(s, e)){mn = INT_MAX;u = e;while(p[u] != -1){mn = min(mn, map[p[u]][u]);u = p[u];}flow_ans += mn;u = e;while(p[u] != -1){map[p[u]][u] -= mn;map[u][p[u]] += mn;u = p[u];} }return flow_ans;}int main(){ofstream fout("ditch.out");ifstream fin("ditch.in");memset(map, 0, sizeof(map));fin >> N >> M;int u, v, w;for(int i = 0; i < N; i++){fin >> u >> v >> w;if(map[u][v]){map[u][v] += w;}else{map[u][v] = w;}}int ans = ek(1, M);fout << ans << endl;}
- USACO 4.2.1 PROB Drainage Ditches
- [USACO 4.2.1] Drainage Ditches
- usaco 4.2.1 Drainage Ditches
- USACO 4.2 Drainage Ditches
- USACO 4.2 Drainage Ditches
- [usaco]4.2.1 最大流问题Drainage Ditches
- 【USACO题库】4.2.1 Drainage Ditches草地排水
- C++——【USACO 4.2.1】——Drainage Ditches
- usaco 4.2 Drainage Ditches 网络流
- USACO 4.2 Drainage Ditches 网络流
- USACO 4.2 草地排水 Drainage Ditches
- USACO 93 Drainage Ditches
- USACO Drainage Ditches解题报告
- 【poj1273】Drainage Ditches 【USACO 93】
- USACO Training 4.2.1 Drainage Ditches 草地排水 题解与分析<网络流DINIC算法>
- 网络流Sap+Gap(【USACO题库】4.2.1 Drainage Ditches草地排水 )
- USACO Section 4.2 Drainage Ditches - 复习网络流
- usaco 4.2 Drainage Ditches(最大流入门题)
- SharePoint 2010 Silverlight webpart 加载超时的问题
- hdu 1172 猜数字 模拟题
- 神奇的 1752年9月
- hdu4562(贪心策略+DP)
- Play on words 之并查集+欧拉回路解题报告
- USACO 4.2.1 PROB Drainage Ditches
- iOS开发资源:FlatUIKit、MMDrawerController以及MZDayPicker等
- 扁平化设计原则
- WP7、Android、iOS技术层面大比拼
- (转)[AndEngine学习教程] 第9节 CollisionDetection 实体碰撞检测
- Python正则表达式指南
- codeforces_38C Blinds
- Android中GridView拖拽的效果
- hdu 2570 迷障 水题