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. typdef void(*fun)(void)笔记【函数指针/typdef函数指针】

    1. 函数指针:返回类型(*函数名)(参数表) 2. 使用typdef void(*fun)(void) typedef的功能是定义新的类型.第一句就是定义了一个MyFun的类型,并定义这种类型为 指 ...

  2. Spark源码剖析 - SparkContext的初始化(五)_创建任务调度器TaskScheduler

    5. 创建任务调度器TaskScheduler TaskScheduler也是SparkContext的重要组成部分,负责任务的提交,并且请求集群管理器对任务调度.TaskScheduler也可以看作 ...

  3. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中

    Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...

  4. 关于CPU的User、Nice、System、Wait、Idle各个参数的解释

    使用Ganglia监控整个Hadoop集群,看到Ganglia采集的各种指标:CPU各个具体的指标含义解释如下: ①CPU(监测到的master主机上的CPU使用情况) 从图中看出,一共有五个关于CP ...

  5. mysql 单表更新记录UPDATE

    1.单表更新 (1)mysql> SELECT * FROM users;+----+----------+----------+-----+------+| id   | username | ...

  6. sql -leetcode 178. Rank Scores

    Score 很好得到: select Score from Scores order by Score desc; 要得到rank, 可以通过比较比当前Score 大的Score 的个数得到: sel ...

  7. grep 打印相关行内容

    grep 打印相关行数常用参数: -r:关键字 -c:打印符合要求的行数 -i:忽略大小写 -n:输出行和行号 -v:打印不符合要求的行,即反选 -A:后跟数字(有无空格都可以),例如 -A3表示打印 ...

  8. loj 6436 PKUSC2018 神仙的游戏

    传送门 好妙蛙 即串\(s\)长度为\(n\)首先考虑如果一个长度为\(len\)的\(border\)存在,当且仅当对所有\(i\in[1,len],s[i]=s[n-len+i]\),也就是所有模 ...

  9. JQuery常见事件

    ##### 事件 onclick 单机事件 ondblclick 双击事件 onmouseover 鼠标穿过 (子盒子独立) onmouseout 鼠标出去 onmouseenter 鼠标进入 (子盒 ...

  10. 20165234 《Java程序设计》第五周学习总结

    第五周学习总结 教材学习内容总结 第七章 内部类与异常类 内部类 内部类:在一个类中定义另一个类. 外嵌类:包含内部类的类,称为内部类的外嵌类. 内部类的类体中不能声明类变量和类方法.外嵌类的类体中可 ...