题目链接:

Drainage Ditches

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 67475   Accepted: 26075

Description

Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. 
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. 
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle. 
 

Input

The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
 

Output

For each case, output a single integer, the maximum rate at which water may emptied from the pond.

Sample Input

5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10

Sample Output

50

题意:

就是求一个1到n的最大流,入门题;

思路:

简直就是模板,有个wa点就是有重边;

AC代码:
//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=2e4+;
int n,m,flow[],path[],cap[][];
queue<int>qu;
int bfs()
{
while(!qu.empty())qu.pop();
mst(path,-);
path[]=;
flow[]=inf;
qu.push();
while(!qu.empty())
{
int fr=qu.front();
qu.pop();
Riep(m)
{
if(i!=&&cap[fr][i]&&path[i]==-)
{
path[i]=fr;
flow[i]=min(cap[fr][i],flow[fr]);
qu.push(i);
}
}
}
if(path[m]==-)return -;
return flow[m];
}
int maxflow()
{
int sum=;
int temp,now,pre;
while()
{
temp=bfs();
if(temp==-)break;
sum+=temp;
now=m;
while(now!=)
{
pre=path[now];
cap[pre][now]-=temp;
cap[now][pre]+=temp;
now=pre;
}
}
return sum;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int u,v,w;
mst(cap,);
Riep(n)
{
scanf("%d%d%d",&u,&v,&w);
cap[u][v]+=w;
}
printf("%d\n",maxflow());
} return ;
}
												

poj-1273 Drainage Ditches(最大流基础题)的更多相关文章

  1. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

  2. poj 1273 Drainage Ditches 最大流入门题

    题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...

  3. Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )

    题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...

  4. POJ 1273 Drainage Ditches 最大流

    这道题用dinic会超时 用E_K就没问题 注意输入数据有重边.POJ1273 dinic的复杂度为O(N*N*M)E_K的复杂度为O(N*M*M)对于这道题,复杂度是相同的. 然而dinic主要依靠 ...

  5. POJ 1273 Drainage Ditches | 最大流模板

    #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...

  6. POJ 1273 Drainage Ditches(最大流Dinic 模板)

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, ...

  7. poj 1273 Drainage Ditches(最大流)

    http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  8. POJ 1273 Drainage Ditches (网络最大流)

    http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  9. poj 1273 Drainage Ditches 网络流最大流基础

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59176   Accepted: 2272 ...

随机推荐

  1. Django实现的博客系统中使用富文本编辑器ckeditor

    操作系统为OS X 10.9.2,Django为1.6.5. 1.下载和安装 1.1 安装 ckeditor 下载地址 https://github.com/shaunsephton/django-c ...

  2. 济南day1

    预计分数:100+100+30 实际分数:10+60+20 T1立方数(cubic) 题目描述 LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8, ...

  3. sprak pom

    <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven ...

  4. HTML5 这些你全知道吗?

    今天心情烦躁,搭建个论坛各种失败,Laravel.React也学不进去,于是就复习复习学过的.记录一下很少用的东西. 代码摘抄于W3C菜鸟教程HTML5手册 # 定义文本方向 <element ...

  5. Maven学习使用Nexus搭建Maven私服

    原文:http://www.cnblogs.com/quanyongan/archive/2013/04/24/3037589.html 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给 ...

  6. 体验Windows 2008 R2的RemoteApp

    [说明]这是<中小企业虚拟机解决方案大全>一书中部分章节的摘抄.该书预计于2009年12月初由<电子工业出版社>出版,敬请期待!   通过远程桌面服务,组织可以为用户提供随时随 ...

  7. SqlServer 数据恢复

    首先看看微软官方的给出的建议(摘自:http://technet.microsoft.com/zh-cn/library/ms189272.aspx): 在从完整恢复模式或大容量日志恢复模式切换前,请 ...

  8. BUPT复试专题—密码(2009)

    题目描述   输入 有多组输入,每组: 第一行:由26个小写字母组成的串以空格隔开,如 b a c e u f g h i j k l m n o p q r s t v w x y z d v y ...

  9. git log 查看版本演变历史

    1.查看git操作历史 $ git log  #git 查看git操作历史 $ git log  --oneline #git 简洁的查看git变更记录 $ git log -n4  --onelin ...

  10. Oracle创建索引的原则(转)

    Oracle 建立索引及SQL优化 数据库索引: 索引有单列索引复合索引之说 如何某表的某个字段有主键约束和唯一性约束,则Oracle 则会自动在相应的约束列上建议唯一索引.数据库索引主要进行提高访问 ...