Power Network POJ - 1459 [网络流模板]
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 [网络流模板]的更多相关文章
- Power Network (poj 1459 网络流)
Language: Default Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 23407 ...
- Power Network POJ - 1459 网络流 DInic 模板
#include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...
- Power Network - poj 1459 (最大流 Edmonds-Karp算法)
Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24788 Accepted: 12922 Description A ...
- F - Power Network - poj 1459(简单最大流)
题目大意:题目说了一大堆,其实都是废话......让人有些不知所云,其实就是给了一些电厂,和一些消费点,然后里面有一些路线什么的,求出消费点可以最多消费的电量是多少. 输入大意: 分析:懂了题意就是一 ...
- F - Power Network POJ - 1459
题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...
- poj 1459 Power Network : 最大网络流 dinic算法实现
点击打开链接 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20903 Accepted: ...
- poj 1459 网络流问题`EK
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24930 Accepted: 12986 D ...
- poj 1459(网络流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 26688 Accepted: 13874 D ...
- 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) ...
随机推荐
- springMVC的全局拦截器
先说说为什么要使用springMVC的全局拦截器,比如 当我们在访问接口的时候,我们一般都会先判断这个用户是否登陆,我们就要在每个接口的前面都要判断一下,想想是不是很蛋疼,那工作量... 这时候,我们 ...
- jmeter元件执行顺序及简介
最近在学习Jmeter,在进行实操之前,先查看了官方文档.因为官方文档是英文的,为了方便以后查看,自己翻译了一部分,中间个别地方根据自己的理解简单地翻译了部分.如果翻译等有问题,欢迎指正. 一.执行顺 ...
- blackeye部署
部署: apt-get install php apt-get install libapache2-mod-php apt-get install git git clone https://git ...
- 混合app开发--js和webview之间的交互总结
使用场景:原生APP内嵌套H5页面,app使用的是webview框架进行嵌套 这样就存在两种情况 1.原生app调用H5的方法 2.H5调用app的方法 分别讲解下,其实app与H5之间的交互式非常简 ...
- eclipse竖向选择快捷键
eclipse的编辑器自带竖向选择功能,在mac上的开启和关闭方法都是command+option+a,在windows下则为alt+shift+a
- 三十三、Linux 进程与信号——中断系统调用和函数可重入性
33.1 中断系统调用 进程调用 “慢” 系统调用时,如果发生了信号,内核会重启系统调用. 慢系统调用 可能会永久阻塞的系统调用 从终端设备.管道或网络设备上的文件读取 向上述文件写入 某些设备上的文 ...
- GCC编译器原理(一)03------GCC 工具:gprof、ld、libbfd、libiberty 和libopcodes
1.3.7 gprof:性能分析工具 参考文档:https://www.cnblogs.com/andashu/p/6378000.html gprof是GNU profile工具,可以运行于linu ...
- Tomcat连接池配置与实现/JNDI
方法一: 在Tomcat的conf/context.xml中配置在Tomcat\apache-tomcat-6.0.33\conf目录下的context.xml文件中配置默认值如下: <?xml ...
- 【核心】project(idea文件)、module(iml文件)到SSM集成、热部署、Tomcat启动、MAVEN依赖冲突
http://wiki.jikexueyuan.com/project/intellij-idea-tutorial/project-composition-introduce.html 在 Inte ...
- pycharm使用方法
https://blog.csdn.net/zhaihaifei/article/details/51658425