hdu_1532_Drainage Ditches
来源:互联网 发布:矩阵测光 编辑:程序博客网 时间:2024/06/06 04:55
#include<iostream> #include<sstream> #include<string> #include<vector> #include<list> #include<set> #include<map>#include<stack> #include<queue> #include<algorithm> #include<numeric> #include<cmath>#include<cstdio>#include<cstdlib>#include<cstring>#pragma warning(disable:4996) using std::cin;using std::cout;using std::endl;using std::stringstream;using std::string;using std::vector;using std::list;using std::pair;using std::set;using std::multiset;using std::map;using std::multimap;using std::stack;using std::queue;using std::priority_queue;const int MaxVexNum = 1000;const int INF = 1000000000;class Edge{public:int to, capacity, flow;Edge(int t, int c, int f){to = t,capacity = c,flow = f;}};class Network{private:int vexnum, edgenum, source, destination,maxflow;vector<vector<Edge>>adjList;public:void addEdge(int from, int to, int cap){adjList[from].push_back({ to, cap, (int)adjList[to].size() });adjList[to].push_back({ from, 0, (int)adjList[from].size() - 1 });}Network(){adjList.resize(MaxVexNum);cin >> edgenum >> vexnum;source = 1, destination = vexnum;for (int i = 0; i < edgenum; i++){int from, to, capacity;cin >> from >> to >> capacity;addEdge(from, to, capacity);}}int dfs(int src, int sink, int flow,vector<bool>&used){if (src == sink){return flow;}used[src] = true;for (int i = 0; i<adjList[src].size(); i++){Edge &edge = adjList[src][i];if (!used[edge.to] && edge.capacity>0){int minflow = dfs(edge.to, sink, std::min(flow, edge.capacity),used);if (minflow>0){edge.capacity -= minflow;adjList[edge.to][edge.flow].capacity += minflow;return minflow;}}}return 0;}void getMaxFlow(){maxflow = 0;while (1){vector<bool>used(MaxVexNum);int f = dfs(source, destination, INF,used);if (!f){return;}maxflow += f;}}void print(){cout << maxflow << endl;}};int main(){//freopen("input.txt", "r", stdin);char ch;while ((ch = cin.get()) != EOF){ungetc(ch,stdin);Network network;network.getMaxFlow();network.print();cin.get();}return 0;}
0 0
- hdu_1532_Drainage Ditches
- Graph Theory NO.9 HDU_1532_Drainage Ditches_最大流
- poj1273Drainage Ditches
- poj_1273Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- Drainage Ditches
- PKU1273Drainage Ditches
- jquery 中的 $(“#”) 与 js中的document.getElementById(“”) 的区别
- 数字在计算机中是如何存储的
- Product of Array except self | leetcode
- uCos-II内存管理
- AWS attach additional disk
- hdu_1532_Drainage Ditches
- Oracle 查询锁之间的依赖关系
- JS,Jquery获取各种屏幕的宽度和高度
- ubuntu 下配置Source Code Pro字体
- 11. Container With Most Water
- 理解dropout
- 二分+树型 dp hdu5682 zxa and leaf
- angularjs-表单验证
- JS大总结(带实例)