题目链接: 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算法)的更多相关文章

  1. 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 ...

  2. poj 1459 Power Network

    题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...

  3. poj 1459 Power Network : 最大网络流 dinic算法实现

    点击打开链接 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20903   Accepted:  ...

  4. 2018.07.06 POJ 1459 Power Network(多源多汇最大流)

    Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...

  5. POJ 1459 Power Network(网络流 最大流 多起点,多汇点)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 22987   Accepted: 12039 D ...

  6. 网络流--最大流--POJ 1459 Power Network

    #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #incl ...

  7. poj 1459 Power Network【建立超级源点,超级汇点】

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 25514   Accepted: 13287 D ...

  8. POJ 1459 Power Network(网络最大流,dinic算法模板题)

    题意:给出n,np,nc,m,n为节点数,np为发电站数,nc为用电厂数,m为边的个数.      接下来给出m个数据(u,v)z,表示w(u,v)允许传输的最大电力为z:np个数据(u)z,表示发电 ...

  9. POJ - 1459 Power Network(最大流)(模板)

    1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...

随机推荐

  1. STM8S TIM4库函数应用

    void TIM4_TimerInit(u8 Timer4Time) { assert_param(IS_TIM4TIMERTIME_OK(Timer4Time)); TIM4_DeInit();// ...

  2. [React] React Fundamentals: Accessing Child Properties

    When you're building your React components, you'll probably want to access child properties of the m ...

  3. [Javascript] The Array map method

    One very common operation in programming is to iterate through an Array's contents, apply a function ...

  4. android内存优化发展——使用软引用

    整个Android开发者一定是遇到了内存溢出这个头疼的问题,一旦这个问题.很难直接决定我们的应用程序是哪里出了问题,为了找到问题的解决方案,必须累积发行通过一些内存分析工具高速定位和强大的体验,现在详 ...

  5. 【课程分享】基于Lucene4.6+Solr4.6+Heritrix1.14+S2SH实战开发从无到有垂直搜索引擎

    对这个课程有兴趣的朋友,能够加我的QQ2059055336和我联系,能够和您分享.  课程介绍:最有前途的软件开发技术--搜索引擎技术  搜索引擎作为互联网发展中至关重要的一种应用,已经成为互联网各个 ...

  6. 什么是Cocos2d-x

    以下是官方对Cocos2d-x的说明."       Cocos2d-x is an open-source mobile 2D game framework, released under ...

  7. Android(java)学习笔记164:Relativelayout相对布局案例

    我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...

  8. felx基础知识

    felx4将功能组件划分为3个命名空间分别是 fx:核心功能 mx:标准flex3组件组 s:新flex4 spark组件组

  9. UIPickerView实现省 市 区三级联动

    前几天用UIPickerView实现了一下三级联动具体的如下图

  10. volatile的使用原则

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/4352802.html ...