这题想了好久,一直认为应该bfs更新后求最小值把发电站最大发电加进去,但是又发现这样求增广路的时候会导致用户更新出错,

加源点和汇点也考虑到了,没想到居然发电量就是超级源到源点的v,居然这么简单@。@

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=,inf=; int v[N][N],s,t,n;
int pre[N];
bool vis[N];
bool bfs()
{
memset(vis,,sizeof vis);
memset(pre,,sizeof pre);
vis[s]=;
queue<int>q;
q.push(s);
while(!q.empty()){
int x=q.front();
if(x==t)return ;
q.pop();
for(int i=;i<=n+;i++)
{
if(!vis[i]&&v[x][i])
{
vis[i]=;
q.push(i);
pre[i]=x;
}
}
}
return ;
}
int max_flow()
{
int ans=;
while(){
if(!bfs())return ans;
int minn=inf+;
for(int i=t;i!=s;i=pre[i])
minn=min(minn,v[pre[i]][i]);
for(int i=t;i!=s;i=pre[i])
{
v[pre[i]][i]-=minn;
v[i][pre[i]]+=minn;
}
ans+=minn;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int np,nc,m;
while(cin>>n>>np>>nc>>m){
memset(v,,sizeof v);
int a,b,c;
char ru;
while(m--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
cin>>ru;
cin>>c;
v[a][b]+=c;
}
while(np--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
v[n][a]=b;
}
while(nc--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
v[a][n+]=b;
}
s=n,t=n+;
cout<<max_flow()<<endl;
}
return ;
}

poj1459网络流之多源点最大流的更多相关文章

  1. Libre 6013 「网络流 24 题」负载平衡 (网络流,最小费用最大流)

    Libre 6013 「网络流 24 题」负载平衡 (网络流,最小费用最大流) Description G 公司有n 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使n ...

  2. Libre 6011 「网络流 24 题」运输问题 (网络流,最小费用最大流)

    Libre 6011 「网络流 24 题」运输问题 (网络流,最小费用最大流) Description W 公司有m个仓库和n个零售商店.第i个仓库有\(a_i\)个单位的货物:第j个零售商店需要\( ...

  3. Libre 6010「网络流 24 题」数字梯形 (网络流,最大费用最大流)

    Libre 6010「网络流 24 题」数字梯形 (网络流,最大费用最大流) Description 给定一个由n 行数字组成的数字梯形如下图所示.梯形的第一行有m 个数字.从梯形的顶部的m 个数字开 ...

  4. Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流)

    Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流) Description 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,-,N).餐厅可以从三种途径获得餐巾. ...

  5. POJ 2135 Farm Tour (网络流,最小费用最大流)

    POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to sh ...

  6. 网络流之最小费用最大流 P1251 餐巾计划问题

    题目描述 一个餐厅在相继的 NN 天里,每天需用的餐巾数不尽相同.假设第 ii 天需要 r_iri​块餐巾( i=1,2,...,N).餐厅可以购买新的餐巾,每块餐巾的费用为 pp 分;或者把旧餐巾送 ...

  7. POJ1459 Power Network(网络最大流)

                                         Power Network Time Limit: 2000MS   Memory Limit: 32768K Total S ...

  8. 网络流_spfa最小费用最大流

    最大流: 不断搜索增广路,寻找最小的容量-流量,得到最大流量,但最大流量在有花费时不一定是最小花费. 最小费用最大流 算法思想: 采用贪心的思想,每次找到一条从源点到达汇点的花费最小的路径,增加流量, ...

  9. [cogs461] [网络流24题#10] 餐巾 [网络流,最小费用最大流]

    建图:从源点向第一层连边,第一层表示当天用掉多少餐巾,第二层表示当天需要多少餐巾,所以注意购买餐巾的边容量为无穷大,要从源点开始连向第二层的点,每天可能有剩余,在第一层内表示为流入第二天的节点.具体见 ...

随机推荐

  1. Sublime 取消每次自动更新弹窗设置

    首选项 --> 设置-用户(英文版  :  "Preferences  - -> "Settings - user"") update_check ...

  2. php 函数__autoload与spl_autoload_register理解

    理解自:http://www.cnblogs.com/myluke/archive/2011/06/25/2090119.html __autoload的作用:当我们在一个页面使用其他文件的类方法时候 ...

  3. Andrew Ng机器学习公开课笔记 -- Generalized Linear Models

    网易公开课,第4课 notes,http://cs229.stanford.edu/notes/cs229-notes1.pdf 前面介绍一个线性回归问题,符合高斯分布 一个分类问题,logstic回 ...

  4. python为什么需要reload(sys)后设置编码

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't deco ...

  5. mysql 数据操作 单表查询 通过四则运算查询

    #通过四则运算查询 FROM employee; AS Annual_salary FROM employee; Annual_salary FROM employee; 查看年薪salary*12 ...

  6. maven解决“Could not calculate build plan”问题

    错误提示如下:(eclipse+maven) Could not calculate build plan: Failure to transfer org.apache.maven.plugins: ...

  7. React package.json详解

    概述: 每个项目的根目录下面,一般都有一个package.json文件,定义了这个项目所需要的各种模块,以及项目的配置信息(比如名称.版本.许可证等元数据).npm install命令根据这个配置文件 ...

  8. [LeetCode] 82. Remove Duplicates from Sorted List II_Medium tag: Linked List

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinctnumbe ...

  9. pxc wsrep_sst_method均配置为xtrabackup-v2报错

    启动第二节点报错:WSREP_SST: [ERROR] Error while getting data from donor node: exit codes: 137 0 本来所有节点的wsrep ...

  10. C++类型前置声明

    前言 本文总结了c++中前置声明的写法及注意事项,列举了哪些情况可以用前置声明来降低编译依赖. 前置声明的概念 前置声明:(forward declaration), 跟普通的声明一样,就是个声明, ...