poj 1459(网络流)
Time Limit: 2000MS | Memory Limit: 32768K | |
Total Submissions: 26688 | Accepted: 13874 |
Description
An example is in figure 1. The label x/y of power station u shows that p(u)=x and pmax(u)=y. The label x/y of consumer u shows that c(u)=x and cmax(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and lmax(u,v)=y.
The power consumed is Con=6. Notice that there are other possible
states of the network but the value of Con cannot exceed 6.
Input
are several data sets in the input. Each data set encodes a power
network. It starts with four integers: 0 <= n <= 100 (nodes), 0
<= np <= n (power stations), 0 <= nc <= n (consumers), and 0
<= m <= n^2 (power transport lines). Follow m data triplets
(u,v)z, where u and v are node identifiers (starting from 0) and 0 <=
z <= 1000 is the value of lmax(u,v). Follow np doublets (u)z, where u is the identifier of a power station and 0 <= z <= 10000 is the value of pmax(u).
The data set ends with nc doublets (u)z, where u is the identifier of a
consumer and 0 <= z <= 10000 is the value of cmax(u).
All input numbers are integers. Except the (u,v)z triplets and the (u)z
doublets, which do not contain white spaces, white spaces can occur
freely in input. Input data terminate with an end of file and are
correct.
Output
each data set from the input, the program prints on the standard output
the maximum amount of power that can be consumed in the corresponding
network. Each result has an integral value and is printed from the
beginning of a separate line.
Sample Input
2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20
7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7
(3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5
(0)5 (1)2 (3)2 (4)1 (5)4
Sample Output
15
6
Hint
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
const int N = ;
const int INF = ;
struct Edge{
int v,w,next;
}edge[N*N];
int head[N];
int level[N];
void addEdge(int u,int v,int w,int &k){
edge[k].v = v,edge[k].w=w,edge[k].next=head[u],head[u]=k++;
edge[k].v = u,edge[k].w=,edge[k].next=head[v],head[v]=k++;
}
int BFS(int src,int des){
queue<int >q;
memset(level,,sizeof(level));
level[src]=;
q.push(src);
while(!q.empty()){
int u = q.front();
q.pop();
if(u==des) return ;
for(int k = head[u];k!=-;k=edge[k].next){
int v = edge[k].v,w=edge[k].w;
if(level[v]==&&w!=){
level[v]=level[u]+;
q.push(v);
}
}
}
return -;
}
int dfs(int u,int des,int increaseRoad){
if(u==des) return increaseRoad;
int ret=;
for(int k=head[u];k!=-;k=edge[k].next){
int v = edge[k].v,w=edge[k].w;
if(level[v]==level[u]+&&w!=){
int MIN = min(increaseRoad-ret,w);
w = dfs(v,des,MIN);
edge[k].w -=w;
edge[k^].w+=w;
ret+=w;
if(ret==increaseRoad) return ret;
}
}
return ret;
}
int Dinic(int src,int des){
int ans = ;
while(BFS(src,des)!=-) ans+=dfs(src,des,INF);
return ans;
} int main(){
int a,b,c,d;
while(cin>>a>>b>>c>>d){
memset(head,-,sizeof(head));
int u,v,w,tot=;
char temp;
for(int i=;i<d;i++){
cin>>temp>>u>>temp>>v>>temp>>w;
if(u==v)continue;
addEdge(u+,v+,w,tot);
}
for(int i=;i<b;i++){
cin>>temp>>u>>temp>>w;
addEdge(,u+,w,tot);
}
for(int i=;i<c;i++){
cin>>temp>>u>>temp>>w;
addEdge(u+,a+,w,tot);
}
printf("%d\n",Dinic(,a+));
}
}
poj 1459(网络流)的更多相关文章
- Power Network POJ - 1459 [网络流模板]
http://poj.org/problem?id=1459 嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点 Status Accepted Time 391ms Memor ...
- Power Network (poj 1459 网络流)
Language: Default Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 23407 ...
- 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) ...
- Power Network POJ - 1459 网络流 DInic 模板
#include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...
- poj 1459 网络流问题`EK
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24930 Accepted: 12986 D ...
- POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)
POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...
- poj 1459 多源多汇点最大流
Sample Input 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 ...
- poj 1459 Power Network : 最大网络流 dinic算法实现
点击打开链接 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20903 Accepted: ...
- POJ 1459 Power Network(网络流 最大流 多起点,多汇点)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 22987 Accepted: 12039 D ...
随机推荐
- Linux基础学习-使用vsftpd服务传输文件
使用vsftpd服务传输文件 1 安装vsftpd [root@qdlinux ~]# yum install vsftpd Loaded plugins: product-id, search-di ...
- Python基础——文件操作
写文件 writefile %%writefile ./data/testFile.txt hello python jin tian tian qi bu cuo open覆盖 txt=open(' ...
- Python学习笔记:面向对象(类)
1.类定义:Python3中,如果新建的类没有继承任何其他类,默认继承基础类object.Python2中如果没有显式继承object类就是经典类,而显式继承了object类就是新式类,Python2 ...
- Anaconda的安装、使用以及与PyCharm的链接
初学Python的盆友们是否有这样的疑惑: 选择Python2还是Python3呢?(后者并不完全兼容前者) 听说两者可以同时安装,那怎么管理呢? Python那么丰富的第三方库,一个一个装太麻烦啦 ...
- 设置eclipse中的${user}
打开eclipse根目录找到eclipse.ini文件增加初始配置: -Duser.name=snzigod@hotmail.com 重启eclipse后${user}变量的值就变成了snzigod@ ...
- 如何用好 Google 等搜索引擎?
看见知乎上如何用好Google搜索的问题(http://www.zhihu.com/question/20161362),整理一下.感谢知乎大神 1.Choose Which Google? HTTP ...
- Windows中redis的下载及安装、设置
本文是转载自:https://www.cnblogs.com/wxjnew/p/9160855.html 除了原文的东西还有自己遇到的一些问题,这里记录一下. 一.下载: 下载地址: https:// ...
- 远程连接MYSQL8.0服务器问题
title: 远程连接MYSQL8.0服务器问题 date: 2018-07-07 11:02:26 updated: tags: [MYSQL,坑] description: keywords: c ...
- luogu2394 yyy loves Chemistry I
练习 #include <iostream> #include <cstdio> using namespace std; long double a; int main(){ ...
- 基于JQuery的WEB套打设计器jatoolsPrinter1.0
开发web套打应用时,如快递单打印,一般要经过以下步骤:1. 扫描快递单据,保存成一个图片文件2. 将底图作成<img>3. 在<img>上放置打印项,试着打印到打印机,观察有 ...