poj 1273 Drainage Ditches
来源:互联网 发布:格式化后数据还能恢复吗 编辑:程序博客网 时间:2024/06/14 14:31
原题链接:http://poj.org/problem?id=1273
最大流模板题。。
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<vector>#include<map>using std::min;using std::find;using std::sort;using std::pair;using std::vector;using std::multimap;#define pb(e) push_back(e)#define sz(c) (int)(c).size()#define mp(a, b) make_pair(a, b)#define all(c) (c).begin(), (c).end()#define iter(c) __typeof((c).begin())#define cls(arr, val) memset(arr, val, sizeof(arr))#define cpresent(c, e) (find(all(c), (e)) != (c).end())#define rep(i, n) for(int i = 0; i < (int)n; i++)#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)const int N = 210;const int INF = 0x3f3f3f3f;struct Ford_Flukerson { struct edge { int to, cap, next, rev; }G[N << 1]; bool vis[N]; int tot, head[N]; inline void init() { tot = 0, cls(head, -1); } inline void add_edge(int u, int v, int cap) { G[tot] = (edge){ v, cap, head[u], tot + 1 }; head[u] = tot++; G[tot] = (edge){ u, 0, head[v], tot - 1 }; head[v] = tot++; } inline void built(int m) { int u, v, f; while(m--) { scanf("%d %d %d", &u, &v, &f); add_edge(u, v, f); } } inline int dfs(int u, int t, int f) { if(u == t) return f; vis[u] = true; for(int i = head[u]; ~i; i = G[i].next) { edge &e = G[i]; if(!vis[e.to] && e.cap > 0) { int d = dfs(e.to, t, min(e.cap, f)); if(d > 0 ) { e.cap -= d; G[e.rev].cap += d; return d; } } } return 0; } inline void max_flow(int n) { int flow = 0; while(true) { cls(vis, false); int f = dfs(1, n, INF); if(!f) break; flow += f; } printf("%d\n", flow); }}go;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout);#endif int n, m; while(~scanf("%d %d", &m, &n)) { go.init(); go.built(m); go.max_flow(n); } return 0;}
0 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
- SpringMVC源码剖析(四)- DispatcherServlet请求转发的
- 音频采样率
- FormsAuthentication.SetAuthCookie函数使用无效
- BZOJ 3668([Noi2014]起床困难综合症-2进制拆分)
- Matrix 手势运动
- poj 1273 Drainage Ditches
- ShellExecuteEx调用第三方程序
- ios8下,alertController之初体验
- 用POI导出excel时,较长的数字不想被自动变为科学计数法的解决方式
- android在线升级apk
- windows下拷贝文件到linux下
- android 使用百度云推送
- spring错误-在spring里面找不到org.springframework.cache.ehcache.EhCacheManagerFactoryBean
- 阿里无线前端招聘内容一览(2)