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的更多相关文章

  1. POJ 1273 Drainage Ditches题解——S.B.S.

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67823   Accepted: 2620 ...

  2. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  3. POJ 1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67387   Accepted: 2603 ...

  4. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  5. POJ-1273 Drainage Ditches 最大流Dinic

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...

  6. POJ 1273 Drainage Ditches -dinic

    dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...

  7. Drainage Ditches(dinic)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59210   Accepted: 2273 ...

  8. Drainage Ditches

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. Drainage Ditches 分类: POJ 图论 2015-07-29 15:01 7人阅读 评论(0) 收藏

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62016 Accepted: 23808 De ...

随机推荐

  1. ZOJ Problem Set - 3865 Superbot (bfs)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p ...

  2. 无法创建链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.Ace.OLEDB.12.0" 的实例。

    --开启导入功能    exec sp_configure 'show advanced options',1    reconfigure    exec sp_configure 'Ad Hoc  ...

  3. hdu1052(田忌赛马 贪心)

    好坑的一道题,不过确实是贪心的一道好题,想了好久一直无法解决平局的情况.  参考了别人的思路,然后结合了自己的想法,总算是想出来了. 这题有些步骤是必须要执行的,有四个步骤 一.当期状态田忌的最慢的马 ...

  4. laravel重要概念和知识点

    Service Provider: 一个laravel service provider就是一个注册IoC container binding的类.实际上,laravel本身就自包含了一堆管理核心框架 ...

  5. poj 1050(DP)

    最大子矩阵和.类似于子序列最大和. // File Name: 1050.cpp // Author: Missa_Chen // Created Time: 2013年06月22日 星期六 17时0 ...

  6. CSS之弧形阴影

    简述 网页上经常会出现一些弧形的阴影效果,看起来很漂亮,下面我们来讲述下如何用CSS来实现一个弧形阴影. 简述 阴影 效果 注释 标题 效果 源码 合并 效果 源码 阴影 效果 首先实现一个简单的阴影 ...

  7. Hack 【二分答案】

    题意:给出n门课程,每一门课程考的分数,每一门课程的学分,求最多删去k组数据之后能够得到的最大加权平均数 先开一个数组x[],其中x[i]=1代表没有删除这门课程,x[i]=0表示删除了这门课程 然后 ...

  8. WEBUS2.0 In Action - 搜索操作指南 - (4)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(3) 6. 搜索多个索引 为了提升性能, 我们可以从多个索引同时进行搜索, Webus.Search.MultiSearcher提供了相 ...

  9. hadoop NameNode 实现分析

    在hadoop 整体分析中,说过nameNode主要是实现一个 blockID 到对应 dataNode的对应关系映射. 现在分析一下腰实现这个映射,nameNode还需要哪些模块. 1 为了方便用户 ...

  10. acdream 1682 吃不完的糖果(环形最大子段和)

    Problem Description 娜娜好不容易才在你的帮助下"跳"过了这个湖,果然车到山前必有路,大战之后必有回复,大难不死,必有后福!现在在娜娜面前的就是好多好多的糖果还有 ...