POJ 1459 Power Network 最大流(Edmonds_Karp算法)
题目链接: http://poj.org/problem?id=1459
因为发电站有多个,所以需要一个超级源点,消费者有多个,需要一个超级汇点,这样超级源点到发电站的权值就是发电站的容量,也就是题目中的pmax,消费者到超级汇点的权值就是消费者的容量,也就是题目中的cmax。初学网络流,第一眼看到这个题还以为应该先做一遍EK算法,然后减去max(p-pmax, c-cmax)呢。。没想到这个题的难点就是建图而已。。
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f;
int cap[][], flow[][], res[], pre[];
int start, end;
int n_node, n_power, n_consumer, n_line;
queue<int>que; int Edmonds_Karp()
{
while(!que.empty())que.pop();
int flow_sum = ;
while(true)
{
memset(res, , sizeof(res));
res[start] = INF;
que.push(start);
while(!que.empty())
{
int u = que.front();
que.pop();
for(int v = ; v < n_node+; v++)
{
if(!res[v] && cap[u][v] > flow[u][v])
{
pre[v] = u;
que.push(v);
res[v] = min(res[u], cap[u][v] - flow[u][v]);
}
}
}
if(res[end] == )break;
for(int u = end; u != start; u = pre[u])
{
flow[pre[u]][u] += res[end];
flow[u][pre[u]] -= res[end];
}
flow_sum += res[end];
}
return flow_sum;
} int main()
{
char fuck_space[];//18禁。。
while(scanf("%d %d %d %d", &n_node, &n_power, &n_consumer, &n_line) != EOF)
{
int u, v, w;
memset(cap, , sizeof(cap));
memset(flow, , sizeof(flow));
start = n_node;
end = n_node+;
for(int i = ; i < n_line; i++)
{
scanf("%s", fuck_space);
sscanf(fuck_space, "(%d,%d)%d", &u, &v, &w);
cap[u][v] += w;
}
for(int i = ; i < n_power; i++)
{
scanf("%s", fuck_space);
sscanf(fuck_space, "(%d)%d", &u, &w);
cap[start][u] += w;
}
for(int i = ; i < n_consumer; i++)
{
scanf("%s", fuck_space);
sscanf(fuck_space, "(%d)%d", &u, &w);
cap[u][end] += w;
}
printf("%d\n", Edmonds_Karp());
}
return ;
}
POJ 1459 Power Network 最大流(Edmonds_Karp算法)的更多相关文章
- 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 Power Network
题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...
- poj 1459 Power Network : 最大网络流 dinic算法实现
点击打开链接 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20903 Accepted: ...
- 2018.07.06 POJ 1459 Power Network(多源多汇最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...
- POJ 1459 Power Network(网络流 最大流 多起点,多汇点)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 22987 Accepted: 12039 D ...
- 网络流--最大流--POJ 1459 Power Network
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #incl ...
- poj 1459 Power Network【建立超级源点,超级汇点】
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25514 Accepted: 13287 D ...
- POJ 1459 Power Network(网络最大流,dinic算法模板题)
题意:给出n,np,nc,m,n为节点数,np为发电站数,nc为用电厂数,m为边的个数. 接下来给出m个数据(u,v)z,表示w(u,v)允许传输的最大电力为z:np个数据(u)z,表示发电 ...
- POJ - 1459 Power Network(最大流)(模板)
1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...
随机推荐
- javascript网页弹出层练习
网页中经常出现很多"popup"弹窗效果,这里做一个练习,给我们初学者一个参考. HTML代码: <div id="popup"></div& ...
- Java反编译器安装及各版本介绍
JAVA语言是1995年5月由SUN公司发布的,由于其安全性高.代码优化.跨平台等特性,迅速取代了很多传统高级语言,占据了企业级网络应用开发等诸多领域的霸主地位. 不过,JAVA最突出 ...
- windows下载安装MariaDB5.5.32 绿色版
1.下载地址: http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/mariadb-5.5.32/win32-packages/mariadb-5.5.32 ...
- 常用加密算法的Java实现(一) ——单向加密算法MD5和SHA
1.Java的安全体系架构 1.1 Java的安全体系架构介绍 Java中为安全框架提供类和接口.JDK 安全 API 是 Java 编程语言的核心 API,位于 java.sec ...
- iostat来对linux硬盘IO性能进行了解
http://www.php-oa.com/2009/02/03/iostat.html
- Open quote is expected for attribute "{1}" associated with an element type "name".
xml属性必须用引号“”,不能缺少.
- HTML增加删除邮件(table)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- acmer -- 最美的情书
2014-09-29 20:51:45 POJ 2482 Fleeting time does not blur my memory of you. Can it really be 4 years ...
- Verilog-1995 VS Verilog-2001
http://www.cnblogs.com/tshell/p/3236476.html 2001年3月IEEE正式批准了Verilog‐2001标准(IEEE1364‐2001),与Verilog‐ ...
- 虚拟机及ubuntu环境搭建问题
1.现象: VMware中ubuntu ping通 宿主机windows VMware中ubuntu ping通 百度 宿主机windows ping不通 VMware中ubuntu 解决办法: 确保 ...