POJ-1273(Dinic)题解 (漂亮版代码)
来源:互联网 发布:圣火明尊盾牌进阶数据 编辑:程序博客网 时间:2024/05/16 15:14
信息课把代码变得漂亮了一些,然而想加上内存优化发现并不可以,FUKK。
#include "queue"#include "cstdio"#include "cstring"using namespace std;#define min(a, b) ((a) < (b) ? (a) : (b))const int MAXN = (int) 200 + 5, oo = 0x3f3f3f3f;int m, n, ne = 1, u, v, c, head[MAXN];struct edge { int to, cap, flow, pre; inline bool adde ( int to, int cap, int flow, int pre ) { this->to = to, this->cap = cap, this->flow = flow, this->pre = pre; }}g[MAXN << 1];inline bool adde( int from, int to, int cap ) { g[++ne].adde( to, cap, 0, head[from] ); head[from] = ne; g[++ne].adde( from, 0, 0, head[to] ); head[to] = ne;}class Dinic{private: int d[MAXN], cur[MAXN], s, t; bool vis[MAXN]; inline bool init() { memset(vis, false, sizeof(vis)); for( register int i = 1; i <= n; ++i ) cur[i] = head[i]; }public: bool bfs(int s, int t) { queue<int> Q; d[s] = 0, vis[s] = true; Q.push(s); while(!Q.empty()) { int u = Q.front(); Q.pop(); for( int i = head[u]; i; i = g[i].pre ) { int v = g[i].to; if( !vis[v] && g[i].cap > g[i].flow ) { vis[v] = true; d[v] = d[u] + 1; Q.push(v); } } } return vis[t]; } inline int dfs( int u, int a ) { if( u == t || !a ) return a; int flow = 0, f; for(register int &i = cur[u]; i; i = g[i].pre ) { int v = g[i].to; if( d[u] + 1 == d[v] && (f = dfs(v, min(g[i].cap - g[i].flow, a))) > 0) { g[i].flow += f; g[i^1].flow -= f; flow += f; a -= f; if(!a) return flow; } } return flow; } int Maxflow( int s, int t ) { this -> s = s, this -> t = t; int flow = 0; while( bfs(s, t) ) { init(); flow += dfs(s, oo); } return flow; }} Dinic;int main() { while(scanf("%d%d", &n, &m) == 2) { ne = 1; memset(head, 0, sizeof(head)); for(register int i = 1; i <= n; ++i ) scanf("%d%d%d", &u, &v, &c), adde(u, v, c); printf("%d\n", Dinic.Maxflow(1, m)); } return 0;}
0 0
- POJ-1273(Dinic)题解 (漂亮版代码)
- POJ-1273(Dinic)题解
- POJ 1273 Drainage Ditches 题解与分析<网络流DINIC>
- POJ 1273 Drainage Ditches (dinic模板)
- POJ 1273 Drainage Ditches(dinic模板)
- poj 1273 Dinic
- POJ 1273 Dinic
- poj 1273 dinic
- POJ 1273&Dinic解决
- poj 1273(dinic....基础题)
- POJ 1273 最大流 Dinic
- POJ 1273 Drainage Ditches -dinic
- 网络流 dinic poj 1273
- 【POJ 1001】Exponentiation 题解&代码(c++)
- 【poj 1003】Hangover 题解&代码(c++)
- POJ 3469 Dinic (二元关系)
- POJ-1273(dinic-最大流,递归实现)
- poj 1273 Drainage Ditches(最大流 dinic模版)
- storm 基本结构及原理
- 通过cloudera manager管理界面添加图表
- SQL中“||”的作用
- 设计模式之迭代器模式(Iterator)
- QuartusII 问题总结
- POJ-1273(Dinic)题解 (漂亮版代码)
- jsessionid 对微信JS SDK 签名的影响
- Android AsyncTask类
- List中对值的改变影响了另一个List的值
- Java1.8集合
- SQL中如何获取记录的排名
- Josephus问题(基于数组的实现)
- 【JavaEE】经典JAVA EE企业应用实战-读书笔记15
- 关于input与IE8的一些事