题目链接: 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 ;
}

最新文章

  1. [LeetCode] Peeking Iterator 顶端迭代器
  2. Angularjs -Promise - $http
  3. symbol table meaning
  4. linux 查找文件与进程常用命令
  5. 4.用PHP打印出前一天的时间格式是2006-5-10 22:21:21
  6. HTTP状态码及其含义
  7. LeetCode:Word Break(DP)
  8. 【Qt】Qt之重启应用程序【转】
  9. 微信移动客户端内部浏览器分享到朋友圈,QQ空间代码
  10. Ubuntu更改hosts档
  11. Springmvc_validation 效验器
  12. TensorFlow 基础知识
  13. React Native实现一个自定义模块
  14. linux使用windows磁盘,挂载共享目录
  15. 注解式controller开发,action找不到controller???
  16. Day10 (黑客成长日记) Urllib库的使用
  17. 3、eclipse集成svn
  18. 复刻smartbits的国产网络测试工具minismb-如何测试路由器
  19. Mysql日期时间Extract函数介绍
  20. VS2017按F1使用中文帮助

热门文章

  1. Html的空格显示
  2. iOS开发之蓝牙通信
  3. qt QSqlQuery
  4. android 开发过程中碰到的 Failed to create the part&#39;s controls 问题
  5. prepare a mysql docker server
  6. Ubuntu14.04服务器安装ftp
  7. hazelcast的坑爹事
  8. maven是什么?(转自oracle官网)
  9. DES加密与解密在GET请求时解密失败的问题
  10. Come and join us at English corner