pku1273 Drainage Ditches
http://poj.org/problem?id=1273
网络流,Dinic
#include <stdio.h>
#include <string.h>
#include <queue> using namespace std; const int inf = <<;
const int maxn = , maxm = ; struct Edge
{
int v, f, nxt;
}; int n, src, sink;
int g[maxn + ];
int nume;
Edge e[maxm* + ]; void addedge(int u, int v, int c)
{
e[++nume].v = v;
e[nume].f = c;
e[nume].nxt = g[u];
g[u] = nume;
e[++nume].v = u;
e[nume].nxt = g[v];
g[v] = nume;
} queue<int> que;
bool vis[maxn + ];
int dist[maxn + ]; void bfs()
{
memset(dist, , sizeof(dist));
while(!que.empty())
{
que.pop();
}
vis[src] = true;
que.push(src);
while(!que.empty())
{
int u = que.front();
que.pop();
for(int i=g[u]; i; i=e[i].nxt)
{
if(e[i].f && !vis[e[i].v])
{
que.push(e[i].v);
dist[e[i].v] = dist[u] + ;
vis[e[i].v] = true;
}
}
}
} int dfs(int u, int delta)
{
if(u == sink)
{
return delta;
}
else
{
int ret = ;
for(int i=g[u]; delta && i; i=e[i].nxt)
{
if(e[i].f && dist[e[i].v] == dist[u] + )
{
int dd = dfs(e[i].v, min(e[i].f, delta));
e[i].f -= dd;
e[i ^ ].f += dd;
delta -= dd;
ret += dd;
}
}
return ret;
}
} int maxflow()
{
int ret = ;
while(true)
{
memset(vis, , sizeof(vis));
bfs();
if(!vis[sink])
{
return ret;
}
ret += dfs(src, inf);
}
} int main()
{
int n, m;
int i, x, y, z;
while(~scanf("%d%d", &m, &n))
{
memset(g, , sizeof(g));
nume = ;
src = ;
sink = n;
for(i=; i<=m; i++)
{
scanf("%d%d%d", &x, &y, &z);
addedge(x, y, z);
}
x = maxflow();
printf("%d\n", x);
}
return ;
}
pku1273 Drainage Ditches的更多相关文章
- POJ 1273 Drainage Ditches题解——S.B.S.
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67823 Accepted: 2620 ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- POJ 1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- POJ 1273 Drainage Ditches -dinic
dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...
- Drainage Ditches(dinic)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59210 Accepted: 2273 ...
- Drainage Ditches
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Drainage Ditches 分类: POJ 图论 2015-07-29 15:01 7人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62016 Accepted: 23808 De ...
随机推荐
- Android findBugs
1.Bug:DM_BOXED_PRIMITIVE_FOR_PARSING "Boxing/unboxing to parse a primitive", A boxed primi ...
- [CF580B]Kefa and Company(滑动窗口)
题目链接:http://codeforces.com/problemset/problem/580/B 某人有n个朋友,这n个朋友有钱数m和关系s两个属性.问如何选择朋友,使得这些朋友之间s最大差距小 ...
- laravel小抄
原文地址:http://cheats.jesse-obrien.ca/ Artisan // Displays help for a given command php artisan --help ...
- CSS之剪切横幅
简述 clip-path属性指定一个应用到元素上的剪切路径.应用在SVG中<clipPath>元素上的属性值可以完全运用在clip-path属性上.还可以使用CSS Shapes模块中的基 ...
- wordpress plugins collection
1/ simple page ordering 4.8星 wordpress的plugins唯一的好处就是命名简单易懂,这款插件从名称就可以看出来,用来对page页面排序的.只需要在后台page中拖拽 ...
- 指针数组vs数组指针 指针函数vs函数指针
在分辨这些重要的概念时,我们先回顾一下前面所讲的C之三值合一,由于三个值所求出的地址是相同的,所以经常有传言说他们都是首元素的地址.这种说法是不正确的.为什么说它是不正确的呢? 首先定义一个指针,将三 ...
- Java Socket 模拟HTTP请求
public static void main(String[] args) { try { String url = "192.168.1.103"; Socket socket ...
- php字符串与正则表达式试题 Zend权威认证试题讲解
字符串是PHP的“瑞士军刀”——作为一种Web开发语言,PHP最常打交道的就是字符串.因此对于开发者来说,处理字符串是一项非常基础的技能.幸运的是,由于PHP开发团队的努力,PHP对字符串的处理相当易 ...
- python练习程序(c100经典例13)
题目: 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数. for i in range(100,1000): a=i/100; b=(i/10)%10; c=i%1 ...
- 安装rlwrap错误的问题解决方法
You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build this program.如果安装rlwra ...