poj-1273 Drainage Ditches(最大流基础题)
题目链接:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 67475 | Accepted: 26075 | 
Description
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
Output
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(最大流基础题)的更多相关文章
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
		
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
 - poj 1273 Drainage Ditches 最大流入门题
		
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
 - Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
		
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
 - POJ 1273 Drainage Ditches 最大流
		
这道题用dinic会超时 用E_K就没问题 注意输入数据有重边.POJ1273 dinic的复杂度为O(N*N*M)E_K的复杂度为O(N*M*M)对于这道题,复杂度是相同的. 然而dinic主要依靠 ...
 - POJ 1273 Drainage Ditches | 最大流模板
		
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...
 - POJ 1273 Drainage Ditches(最大流Dinic 模板)
		
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, ...
 - poj 1273 Drainage Ditches(最大流)
		
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
 - POJ 1273 Drainage Ditches (网络最大流)
		
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
 - poj 1273  Drainage Ditches  网络流最大流基础
		
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59176 Accepted: 2272 ...
 
随机推荐
- HDu1241 DFS搜索
			
#include<iostream> #include<cstring> using namespace std; int a[105][105]; int d[8][2]={ ...
 - Angular Material & Hello World
			
前言 Angular Material(下称Material)的组件样式至少是可以满足一般的个人开发需求(我真是毫无设计天赋),也是Angular官方推荐的组件.我们通过用这个UI库来快速实现自己的i ...
 - CodeWar---将字符串转换为驼峰命名
			
Convert string to camel case 将字符串转换为驼峰命名 自己的解法 将不是字母和数字的字符用.取代,再根据点划分数组.将下标不为0的数组首字符大写,剩下全部小写 static ...
 - PythonCookbook读书笔记
			
第一章 数据结构和算法 1.1 将序列分解为单独的变量 适用于元组.列表.字符串等.只要是可迭代的对象,都可以执行分解操作.唯一的要求是变量的总数和结构要与序列相同. 1.2 从任意长度的可迭代对象中 ...
 - [Javascript] Convert a Callback-Based JavaScript Function to a Promise-Based One
			
Sometimes, you might want to convert a JavaScript function that accepts a callback to one that retur ...
 - 高速清除winXP系统中explorer.exe病毒
			
关于这个explorer.exe病毒.是眼下xp最为常见的一个病毒,会大量的消耗系统资源,造成电脑特别的卡顿. 1.关闭还原(假设没有,则跳过),为的是防止我们改动后,还原之后又回来了. 2.打开注冊 ...
 - SODBASE CEP学习(四)续:类SQL语言EPL与Storm或jStorm集成-使用分布式缓存
			
流式计算在一些情况下会用到分布式缓存,从而实现(1)想把统计或计算结果保存在分布缓存中.供其他模块或其他系统调用. (2)某一滑动时间窗体上计数.比如实时统计1小时每一个Cookie的訪问量.实时统计 ...
 - Androidclient验证Licence的原理
			
需求 限制App的使用,使App仅仅能在有许可的设备上执行. 分析及解决方式 原理 让App在每次执行的时候都连接server进行合法性验证--当然是一个非常成熟可靠的方案. 可是这样做的局限也是每次 ...
 - FragmentSharedFabTransition
			
https://github.com/lgvalle/FragmentSharedFabTransition
 - fruitstrap 安装.app文件
			
1. 下载ipa的ios文件然后解压成.app的文件 2. 进入fruitstrap文件夹,copy .app文件到fruitstrap文件夹中 执行./fruitstrap -b umetrip.a ...