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 ...
随机推荐
- H5移动前端完美布局之-margin百分比的使用
一 ,背景 在移动端页面开发我们经常会遇到一件尴尬的事 我们所开发出来的页面跟设计师所给的页面差别很大 再加上移动设备屏幕的大小不一出来的效果更是参差不齐 然后.... 当然 现实情况没有这么糟糕.. ...
- PHP包含文件函数include、include_once、require、require_once区别总结
一.使用语法和简介 1.include() 语法:include(/path/to/filename)include()语句将在其被调用的位置处包含一个文件.包含一个文件与在该语句所在位置复制制定文件 ...
- Java NIO读书笔记
一.Java IO与NIO区别: (1)Java NIO提供了与标准IO不同的IO工作方式: Channels and Buffers(通道和缓冲区):标准的IO基于字节流和字符流进行操作的,而NIO ...
- HTML+CSS+JAVASCRIPT 总结
1. HTML 1: <!doctype html> 2: <!-- This is a test html for html, css, javascript --> 3: ...
- 五款好玩又好用的Linux网络测试和监控工具
五款好玩又好用的Linux网络测试和监控工具 [51CTO精选译文]在这篇介绍几款Linux网络测试实用工具的文章中,我们使用Bandwidthd.Speedometer.Nethogs.Darkst ...
- UIScrollView 期本使用方法
UIScrollView 1. contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...
- 基于HtmlUnit的模板的网页数据抽取
既然方向定了,就开始做实验室吧,做舆情分析,首先就是要收集相关的语料 正好实验室有同学在做标化院的信息抽取抽取这块 于是把程序拿过来研究研究正好 完整程序在126邮箱共享: 可下载数:20 共享连接 ...
- js解决快速回车重复订单提交(客户端方式)
Html代码: <form action="order_add_data.php" method="post" name="order_adds ...
- Linux VPS 基本命令
我们Linux VPS用命令才能管理他,我们来罗列一些基本和简单的Linux的命令 1.lsls / 查看根目录ls -a / 查看根目录下所要文件,包括隐藏文件ls -l / 详细列出目录下文件的权 ...
- EIG集团简单介绍
有朋友会问为什么要介绍EIG集团,他们是干什么的?与域名.主机.IDC行业资讯等有啥关系?EIG集团很牛逼么?带着这些疑问,简单的给大家做个介绍,希望能帮助大家了解这个IDC行业里面的“魔鬼”! EI ...