HDOJ 1532 Drainage Ditches
来源:互联网 发布:在线教育直播平台源码 编辑:程序博客网 时间:2024/04/28 04:32
题意:有一个n个点和m条边的网络,每条边都有流量上限,求从点1到点n的最大流量
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532
思路:网络流dinic模板
注意点:无
以下为AC代码:
Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor131511342015-03-16 22:56:54Accepted15320MS1684K4234 BC++luminous11#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <cstring>#include <cstdio>#include <string>#include <vector>#include <deque>#include <list>#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <cctype>#include <climits>#include <iomanip>#include <cstdlib>#include <algorithm>//#include <unordered_map>//#include <unordered_set>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define RDI(a) scanf ( "%d", &a )#define RDII(a, b) scanf ( "%d%d", &a, &b )#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c )#define RS(s) scanf ( "%s", s )#define PI(a) printf ( "%d", a )#define PIL(a) printf ( "%d\n", a )#define PII(a,b) printf ( "%d %d", a, b )#define PIIL(a,b) printf ( "%d %d\n", a, b )#define PIII(a,b,c) printf ( "%d %d %d", a, b, c )#define PIIIL(a,b,c) printf ( "%d %d %d\n", a, b, c )#define PL() printf ( "\n" )#define PSL(s) printf ( "%s\n", s )#define rep(i,m,n) for ( int i = m; i < n; i ++ )#define REP(i,m,n) for ( int i = m; i <= n; i ++ )#define dep(i,m,n) for ( int i = m; i > n; i -- )#define DEP(i,m,n) for ( int i = m; i >= n; i -- )#define repi(i,m,n,k) for ( int i = m; i < n; i += k )#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )#define depi(i,m,n,k) for ( int i = m; i > n; i += k )#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )#define READ(f) freopen(f, "r", stdin)#define WRITE(f) freopen(f, "w", stdout)using namespace std;const double pi = acos(-1);template <class T>inline bool RD ( T &ret ){ char c; int sgn; if ( c = getchar(), c ==EOF )return 0; //EOF while ( c != '-' && ( c < '0' || c > '9' ) ) c = getchar(); sgn = ( c == '-' ) ? -1 : 1; ret = ( c == '-' ) ? 0 : ( c - '0' ); while ( c = getchar() , c >= '0' && c <= '9' ) ret = ret * 10 + ( c - '0' ); ret *= sgn; return 1;}inline void PD ( int x ){ if ( x > 9 ) PD ( x / 10 ); putchar ( x % 10 + '0' );}const double eps = 1e-10;const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };struct edge{ int to, f, e; edge(){} edge( int _to, int _f, int _e ) : to(_to), f(_f), e(_e) {}};const int MAXN = 205;const int INF = 0x3f3f3f3f;int n, m;vector<edge> g[MAXN];bool vis[MAXN];int dis[MAXN];queue<int> q;int be, en;void init(){ while ( ! q.empty() ) q.pop(); rep ( i, 0, MAXN ) g[i].clear();}int dfs ( int u, int f ){ if ( u == en ){ return f; } else{ int ret = 0; rep ( i, 0, g[u].size() ){ if ( f == 0 )break; if ( g[u][i].f != g[u][i].e && dis[g[u][i].to] == dis[u] + 1 ){ int dd = dfs ( g[u][i].to, min ( g[u][i].e - g[u][i].f, f ) ); g[u][i].f += dd; f -= dd; ret += dd; } } return ret; }}void bfs (){ vis[be] = 1; q.push ( be ); while ( ! q.empty() ){ int u = q.front(); q.pop(); rep ( i, 0, g[u].size() ){ if ( ! vis[g[u][i].to] && g[u][i].e != g[u][i].f ){ dis[g[u][i].to] = dis[u] + 1; vis[g[u][i].to] = 1; q.push ( g[u][i].to ); } } }}void print(){ rep ( i, 0, m ){ rep ( j, 0, g[i].size() ){ cout << " i : " << i << " to : " << g[i][j].to << " f : " << g[i][j].f << " e : " << g[i][j].e << endl; } }}int maxflow(){ int f = 0; while ( 1 ){ clr ( vis, 0 ); clr ( dis, 0 ); bfs(); if ( vis[en] == false ) return f; f += dfs ( be, INF ); }}int main(){ int a, b, c; while ( RDII ( n, m ) != EOF ){ init(); be = 1; en = m; rep ( i, 0, n ){ RDIII ( a, b, c ); g[a].push_back ( edge ( b, 0, c ) ); } int ans = maxflow(); PIL ( ans ); } return 0;}
0 0
- HDOJ 1532 Drainage Ditches
- hdoj 1532 Drainage Ditches
- hdoj 1532 Drainage Ditches
- 【最大流】HDOJ 1532 Drainage Ditches
- poj 1273 Drainage Ditches | hdoj 1532
- HDOJ 1532 Drainage Ditches(最大流)
- HDOJ-1532 Drainage Ditches(网络流)
- 【HDOJ 1532】 Drainage Ditches(最大流模板)
- hdoj 1532 Drainage Ditches 【最大流---裸题】
- hdoj 1532 Drainage Ditches (最大流)
- hdoj 1532 Drainage Ditches 题解(最大流)
- HDOJ 题目1532 Drainage Ditches(最大流)
- hdoj--1532 Drainage Ditches(网络流/最大流)
- HDOJ 1532 Drainage Ditches (Ford-Fulkerson + EK + Dinic)
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- HDU 1532 Drainage Ditches
- hdu 1532 Drainage Ditches
- uva 10405 LCS + 空格卡wa
- ZOJ 3483 Gaussian Prime(数学啊 )
- MQTT协议笔记之-连接和心跳
- delphi5安装教程
- 计算机网络基础笔记1
- HDOJ 1532 Drainage Ditches
- Eclipse里面的快捷键小记
- 【ok】获取文件夹下所有文件(包括文件夹)
- 状态模式
- 杭电 HDU ACM 1334 Perfect Cubes
- Android 中WebView调用JS的跨域问题
- 编译烧写norflash的程序时keil的配置
- android跨进程事件注入(程序模拟用户输入,getevent与sendevent)
- 架构设计案例分析-高速公路收费运营管理平台