http://poj.org/problem?id=1459

嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点

Status Accepted
Time 391ms
Memory 1588kB
Length 2166
Lang G++
Submitted 2018-05-23 14:43:22
Shared
RemoteRunId 18625420

#include <iostream>
#include <string.h>
#include <cmath>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(a,b) cout<<#a<<'['<<b<<"]="<<b[a]<<endl
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const ll INF=0x3f3f3f3f3f;
int casn,n,np,nc,m,k;
struct node {int to;ll cap;int next;}e[maxm];
int ss,tt,head[maxn],nume,dis[maxn],q[maxn];
inline void addx(int a,int b,ll c){
e[++nume]=(node){b,c,head[a]};
head[a]=nume;
}
inline void add(int a,int b,ll c){
addx(a,b,c);addx(b,a,0);
}
bool bfs(int s=ss,int t=tt){
int top=0,end=1;
q[0]=s;
for(int i=0;i<=t;i++) dis[i]=0;
dis[s]=1;
while(top!=end){
int now=q[top++];top%=maxn;
for(int i=head[now];i;i=e[i].next){
int to=e[i].to;
if(!dis[to]&&e[i].cap){
dis[to]=dis[now]+1;
if(to==t)break;
q[end++]=to;end%=maxn;
}
}
}
return dis[t];
}
ll dfs(int now=ss,ll last=INF){
if(now==tt)return last;
ll flow=0,det;
for(int i=head[now];i;i=e[i].next){
int to=e[i].to;
if(e[i].cap&&dis[to]==dis[now]+1){
det=dfs(to,min(last-flow,e[i].cap));
flow+=det;
e[i].cap-=det;
e[i^1].cap+=det;
if(flow==last) return last;
}
}
if(flow==0) dis[now]=-1;
return flow;
} int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
int nc,np;
IO;
while(cin>>n>>np>>nc>>m){
char ch;
memset(head,0,sizeof head);
nume=1;
ss=n+9,tt=n+10;
rep(i,1,m) {
int a,b,c;
cin>>ch>>a>>ch>>b>>ch>>c;
if(a==b) continue;
add(a,b,c);
}
rep(i,1,np){
int a,b,c;
cin>>ch>>a>>ch>>c;
add(ss,a,c);
}
rep(i,1,nc){
int a,b,c;
cin>>ch>>a>>ch>>c;
add(a,tt,c);
}
int ans=0;
while(bfs()){
// show(1);
ans+=dfs();
// show(ans); }
cout<<ans<<'\n';
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

Power Network POJ - 1459 [网络流模板]的更多相关文章

  1. Power Network (poj 1459 网络流)

    Language: Default Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 23407   ...

  2. Power Network POJ - 1459 网络流 DInic 模板

    #include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...

  3. Power Network - poj 1459 (最大流 Edmonds-Karp算法)

      Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24788   Accepted: 12922 Description A ...

  4. F - Power Network - poj 1459(简单最大流)

    题目大意:题目说了一大堆,其实都是废话......让人有些不知所云,其实就是给了一些电厂,和一些消费点,然后里面有一些路线什么的,求出消费点可以最多消费的电量是多少. 输入大意: 分析:懂了题意就是一 ...

  5. F - Power Network POJ - 1459

    题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...

  6. poj 1459 Power Network : 最大网络流 dinic算法实现

    点击打开链接 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20903   Accepted:  ...

  7. poj 1459 网络流问题`EK

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24930   Accepted: 12986 D ...

  8. poj 1459(网络流)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 26688   Accepted: 13874 D ...

  9. POJ 1459 网络流 EK算法

    题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...

随机推荐

  1. Docker 容器管理

    单一容器管理 容器的标识符 每个容器被创建后都会分配一个CONTAINER_ID作为容器的唯一标识符,后续的启动.停止等操作都通过CONTAINER_ID来完成的. CONTAINER_ID很难记忆, ...

  2. 在js或jquery中动态添加js脚本【转】

    起因: 我们在用js动态写入script时,会导致</script>后面的所有语句都变为普通文本,导致html展示无效, 所以我们需要规避</script>问题. 解决方案一( ...

  3. jquery遇到的问题

    1.关于$.fn $.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 如扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法, ...

  4. Oracle的 listagg() WITHIN GROUP ()函数使用

    1.使用条件查询  查询部门为20的员工列表 -- 查询部门为20的员工列表    SELECT t.DEPTNO,t.ENAME FROM SCOTT.EMP t where t.DEPTNO = ...

  5. sqlalchemy数据库分层操作

    在学习sqlalchemy操作中,最常见的就是如下的示例,一个文件基本上包含了数据库的增删改查.sqlalchemy的具体操作我就不再详细说明了.流程大概是: 定义表 创建数据库引擎 创建表 插入数据 ...

  6. 添加Glide图片加载框架依赖

    1.添加依赖implementation 'com.github.bumptech.glide:glide:4.7.1' 2.放置一个ImageView.3.加载,ivGif是ImageView实例 ...

  7. 传入mybatis的xml为Long型时报There is no getter for property named 'VARCHAR' in

    修改前   <insert id="insert" parameterType="com.taotao.pojo.TbContent" >    i ...

  8. easyui 进阶之表单校验、自定义校验

    前言 easyui是一种基于jQuery的用户界面插件集合,它为创建现代化,互动,JavaScript应用程序,提供必要的功能,完美支持HTML5网页的完整框架,节省网页开发的时间和规模.非常的简单易 ...

  9. webpack 优化

    1 优化loader配置 1.1 缩小文件匹配范围(include/exclude)   通过排除node_modules下的文件 从而缩小了loader加载搜索范围 高概率命中文件  module: ...

  10. Python之 string 和 random方法

    1. import string import string print(string.ascii_lowercase) #输出全部小写字母a-z print(string.ascii_letters ...