1993 草地排水

时间限制: 2 s    空间限制: 256000 KB    题目等级 : 钻石 Diamond

题目描述 Description

在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水。这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间。因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没的烦恼(不用担心,雨水会流向附近的一条小溪)。作为一名一流的技师,农夫约翰已经在每条排水沟的一端安上了控制器,这样他可以控制流入排水沟的水流量。

农夫约翰知道每一条排水沟每分钟可以流过的水量,和排水系统的准确布局(起点为水潭而终点为小溪的一张网)。需要注意的是,有些时候从一处到另一处不只有一条排水沟。

根据这些信息,计算从水潭排水到小溪的最大流量。对于给出的每条排水沟,雨水只能沿着一个方向流动,注意可能会出现雨水环形流动的情形。

输入描述 Input Description

第1行: 两个用空格分开的整数N (0 <= N <= 200) 和 M (2 <= M <= 200)。N是农夫John已经挖好的排水沟的数量,M是排水沟交叉点的数量。交点1是水潭,交点M是小溪。

第二行到第N+1行: 每行有三个整数,Si, Ei, 和 Ci。Si 和 Ei (1 <= Si, Ei <= M) 指明排水沟两端的交点,雨水从Si 流向Ei。Ci (0 <= Ci <= 10,000,000)是这条排水沟的最大容量。

输出描述 Output Description

输出一个整数,即排水的最大流量。

样例输入 Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
样例输出 Sample Output

50

 #include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
#define INF 0x7f
int n,m,map[][]={},lays[];
bool vis[];
bool BFS(){
queue<int>q;
memset(lays,-,sizeof(lays));
lays[]=;q.push();
while(!q.empty()){
int u=q.front();q.pop();
for(int i=;i<=m;i++){
if(map[u][i]>&&lays[i]==-){
lays[i]=lays[u]+;
if(i==m)return ;
else q.push(i);
}
}
}
return ;
}
int Dinic(){
int maxf=;vector<int>st;
while(BFS()){
st.push_back();
memset(vis,,sizeof(vis));vis[]=;
while(!st.empty()){
int p=st.back();
if(p==m){
int minn,minx=INF;
for(int i=;i<st.size();i++){
int u=st[i-],v=st[i];
if(map[u][v]>&&map[u][v]<minx){
minn=u;minx=map[u][v];
}
}
maxf+=minx;
for(int i=;i<st.size();i++){
int u=st[i-],v=st[i];
map[u][v]-=minx;
map[v][u]+=minx;
}
while(!st.empty()&&st.back()!=minn){
vis[st.back()]=;st.pop_back();
}
}
else {
int i;
for(i=;i<=m;i++){
if(map[p][i]>&&lays[i]==
lays[p]+&&!vis[i]){
vis[i]=;st.push_back(i);
break;
}
}
if(i>m)st.pop_back();
}
}
}
return maxf;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=,a,b,c;i<=n;i++){
scanf("%d%d%d",&a,&b,&c);
map[a][b]+=c;
}
printf("%d\n",Dinic());
return ;
}

Codevs 1993 草地排水的更多相关文章

  1. codevs 1993草地排水

    1993 草地排水

  2. 模板题 codevs 1993 草地排水 想学习的请看链接

    不能再水的题了. Dinic算法,比EK更快. 想要学习请看链接   https://comzyh.com/blog/archives/568/ 并附上我的模板(其实和comzyh大神的一样) #in ...

  3. codevs 1993 草地排水 USACO

    /*Dinic*/ #include<iostream> #include<cstdio> #include<cstring> #include<queue& ...

  4. CODEVS——T 1993 草地排水 USACO

    http://codevs.cn/problem/1993/  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 De ...

  5. 【CodeVS】1993草地排水

    题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...

  6. 【最大流】【CODEVS】1993 草地排水

    [算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...

  7. AC日记——草地排水 codevs 1993

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  8. - > 网络流(【最大流】草地排水模板题)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 在农夫约翰的农场上,每 ...

  9. codevs1993 草地排水(最大流)

    1993 草地排水 USACO  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 在农夫约翰的农场上,每逢下雨,Bes ...

随机推荐

  1. rand()和srand()

    C++中rand() 函数的用法 1.rand()不需要参数,它会返回一个从0到最大随机数的任意整数,最大随机数的大小通常是固定的一个大整数. 2.如果你要产生0~99这100个整数中的一个随机整数, ...

  2. Java 获取Web项目相对webapp地址

    例如, import java.io.File; import java.io.FileInputStream; import javax.servlet.http.HttpServletReques ...

  3. Linux常用关机重启命令

    # shutdown -h 10       //计算机将在10分钟后 关机,且会显示在登录用户的当前屏幕中 # shutdown -h now    //立即 关机 # shutdown -h 20 ...

  4. JZOJ 4743. 积木

    Description Input Output Sample Input 38 7 63 9 41 10 5 Sample Output 18

  5. Oracle两种临时表的创建与使用详解

    ORACLE数据库除了可以保存永久表外,还可以建立临时表temporary tables.这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据.当会话退出或者用户提交comm ...

  6. Memory loss【记忆缺失】

    Memory Loss Losing your ability to think and remember is pretty scary. We know the risk of dementia ...

  7. Farm Tour POJ - 2135 (最小费用流)

    When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= ...

  8. Kinect安装

    在连接kinect机器前,需要先安装两个软件,而在安装这两个软件前需要有vs2010(专业版本和快速版),因为需要包含.net framework 4.0 kinect sdk http://www. ...

  9. TypeError: cannot perform reduce with flexible type

    想要解决这个错误,最好先明白numpy数据类型的dtype转换 生成一个浮点数组 a=np.random.random(4) 输出 a array([0.0945377,0.52199916,0.62 ...

  10. javascript 实现九九乘法表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...