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) ...
随机推荐
- 【坑】zsh和oh-my-zsh卸载后导致无法登陆
apt-get remove zsh 然后断开终端,就再也连不上了,崩溃啊! 以下登陆为www用户登陆 各种找,到这里 https://www.cnblogs.com/EasonJim/p/78630 ...
- python学习路线--从入门到入土
入门技术博客 进阶自己挑选 入门基础 Python入门相对容易又可以干很多事(网站,运维,数据,爬虫等),是一门方便的工具语言.2016年TIOBE排名显示Python已经名列第四,成为脚本语言之首. ...
- Mongoose笔记
Mongoose是在node.js异步环境下对mongodb进行便捷操作的对象模型工具 mongoose是针对mongoDB操作的一个对象模型库,封装了mongoDB对文档的.增删改查等方法 使用Ko ...
- ZooKeeper基础
======================================ZooKeeper 背景======================================ZooKeeper 是一 ...
- 设置 Visual Studio IIS Express 站点局域网访问
Ø Visual Stuido 的 IIS Express运行一个网站时,默认地址是这样的:http://localhost:23167/Cache/Three,其中 localhost 表示本机, ...
- 浅谈style.,currentStyle,getComputedStyle,getAttribute
xxx为属性. ele为元素. 1.style.是针对于样式 在前面的一篇博客中我也有说到,ele.style.xxx; 通常用于赋值,赋值也是针对于行内样式,用它来取值的话,它只能取到内联样式. 今 ...
- [译]Walkthrough: Using MSBuild
原文 MSBuild是微软VS的Build平台. 你可以在Visual Studio或Windows命令行中运行MSBuild.在这我们使用VS创建一个MSBuild项目.你可以在VS中编辑项目文件, ...
- spring cloud心跳检测自我保护(EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.)
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER ...
- windows server 2012 配置多用户ftp服务器配置注意点
1.ftp根目录配置“FTP授权规则”为: 2.配置“FTP用户隔离”为: 3.配置“FTP目录浏览”为: 4.ftp虚拟目录“FTP授权规则”配置为:
- 表单相关标签之form标签
表单能够包含 input 元素,比如文本字段.复选框.单选框.提交按钮等等. 表单还可以包含 menus.textarea.fieldset.legend 和 label 元素以及其它块级元素 表单用 ...