题目链接

Description

A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= pmax(u) of power, may consume an amount 0 <= c(u) <= min(s(u),cmax(u)) of power, and may deliver an amount d(u)=s(u)+p(u)-c(u) of power. The following restrictions apply: c(u)=0 for any power station, p(u)=0 for any consumer, and p(u)=c(u)=0 for any dispatcher. There is at most one power transport line (u,v) from a node u to a node v in the net; it transports an amount 0 <= l(u,v) <= lmax(u,v) of power delivered by u to v. Let Con=Σuc(u) be the power consumed in the net. The problem is to compute the maximum value of Con.
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

There 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

For 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

AC

  • 建图

    1. 源点和所有的发电站建边,流量为产量
    2. 根据题目给的供电线,建边
    3. 消费者到汇点建边,流量为消耗量
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 110
#include <cstring>
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;
struct ac{int v, c, pre;
}edge[20500];
int head[N], dis[N], curedge[N], cnt;
int inf = 0x3f3f3f3f;
int n, np, nc, m;
void addedge(int u, int v, int c) {edge[cnt].v = v;edge[cnt].c = c;edge[cnt].pre = head[u];head[u] = cnt++;swap(u, v);edge[cnt].v = v;edge[cnt].c = 0;edge[cnt].pre = head[u];head[u] = cnt++;
}
bool bfs(int s, int e) {queue<int> que;que.push(s);memset(dis, 0, sizeof(dis));dis[s] = 1;while (!que.empty()) {int t = que.front();que.pop();for (int i = head[t]; i != -1; i = edge[i].pre) {if (dis[edge[i].v] || edge[i].c == 0)   continue;dis[edge[i].v] = dis[t] + 1;que.push(edge[i].v);} }return dis[e] != 0;
}
int dfs(int s, int e, int flow) {if (s == e) return flow;for (int &i = curedge[s]; i != -1; i = edge[i].pre) {if (dis[edge[i].v] == dis[s] + 1 && edge[i].c) {int d = dfs(edge[i].v, e, min(flow, edge[i].c));if (d > 0) {edge[i].c -= d;edge[i ^ 1].c += d;return d; }}}return 0;
}
int solve(int s, int e) {int sum = 0;while (bfs(s, e)) {for (int i = 0; i <=  n + 1; ++i) {curedge[i] = head[i];}int d;while (d = dfs(s, e, inf)) {sum += d;}}return sum;
}int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifwhile (cin >> n) {memset(head, -1, sizeof(head));cnt = 0;cin >> np >> nc >> m;// m条线路建边 int start = n, end = n + 1; for (int i = 0; i < m; ++i) {char c;int s, e, w;cin >> c >> s >> c >> e >> c >> w;addedge(s, e, w);}// 源点和发电站之间建边 for (int i = 0; i < np; ++i) {char c;int x, y;cin >>c >> x >> c >> y; addedge(start, x, y);}// 消费者和汇点建边 for (int i = 0; i < nc; ++i) {char c;int x, y;cin >> c >> x >> c >> y;addedge(x, end, y);}int ans = solve(start, end);cout << ans <<endl;}return 0;
}

POJ 1459 -- Power Network(最大流, 建图)相关推荐

  1. POJ - 1459 Power Network(网络流-最大流)

    题目链接:点击查看 题目大意:题意属实恶心,借用别的大佬的题意: 题目描述 一个电网包含一些结点(电站.消费者.调度站),这些结点通过电线连接.每个结点 uu 可能被供给 s(u) 的电能, s(u) ...

  2. 初涉网络流 POJ 1459 Power Network

    怒搞一下午网络流,又去我一块心病. 从2F到SAP再到Dinic最终过掉了. 但是书上说Dinic的时间复杂度为v*v*e.感觉也应该超时的啊,但是过掉了,好诡异. 后两种算法都是在第一种的基础上进行 ...

  3. POJ 1459 Power Network

    题意:有n个据点,np个发电机.nc个用户,m条电线.给出发电机.用户.电线的电流限制,求最大网络电流. 这是带节点的网络流.事实上和原来没什么差别,仅仅要在前后都添加一个据点,在这里我加了0和n+1 ...

  4. POJ 1149 最大流建图 PIGS

    题意: 给出猪圈个数 m 和买家人数 n 然后给出m个猪圈的猪的头数.. 接下来 n 行.. 给出mm a1 a2 .. a(mm) k 例如 2 1 5 3 表示第i+1个用户 有mm(2) 个猪圈 ...

  5. Invitation Cards POJ - 1511 SPFA(dijkstra+反向建图+邻接表(下标过大)+输入输出用stdio(iostream超时))

    题目大意: 有编号1-P的站点, 有Q条公交车路线,公交车路线只从一个起点站直接 到达终点站,是单向的,每条路线有它自己的车费.有P个人早上从1出发 ,他们要到达每一个公交站点, 然后到了晚上再返回点 ...

  6. POJ1459 Power Network —— 最大流

    题目链接:https://vjudge.net/problem/POJ-1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Tot ...

  7. Codeforces 362E Petya and Pipes 费用流建图

    题意: 给一个网络中某些边增加容量,增加的总和最大为K,使得最大流最大. 费用流:在某条边增加单位流量的费用. 那么就可以2个点之间建2条边,第一条给定边(u,v,x,0)这条边费用为0 同时另一条边 ...

  8. BZOJ4205卡牌配对——最大流+建图优化

    题目描述 现在有一种卡牌游戏,每张卡牌上有三个属性值:A,B,C.把卡牌分为X,Y两类,分别有n1,n2张. 两张卡牌能够配对,当且仅当,存在至多一项属性值使得两张卡牌该项属性值互质,且两张卡牌类别不 ...

  9. POJ 2312Battle City(BFS-priority_queue 或者是建图spfa)

    1 /* 2 bfs搜索!要注意的是点与点的权值是不一样的哦! 3 空地到空地的步数是1, 空地到墙的步数是2(轰一炮+移过去) 4 所以用到优先队列进行对当前节点步数的更新! 5 */ 6 #inc ...

最新文章

  1. linux 蓝牙脚本,arm linux串口蓝牙工具移植及使用(示例代码)
  2. 第三周课程总结及实验报告(一)
  3. 三、ResNet50预置算法提高美食分类识别精确度
  4. linux阿帕奇日志文件,Linux下apache日志文件设置
  5. Black Hat 2017黑帽大会:8款值得一看的黑客工具
  6. geoTools学习笔记001---(简介)
  7. go设置linux ip,设置linux虚拟机的静态ip-Go语言中文社区
  8. php 405,php Restler 405 Method Not Allowed 问题解决啦,restlerallowed_PHP教程
  9. linux/windows_powershell/bash_硬链接Hardlink/软连接(符号链接)创建以及注意事项/powershell_获取文件绝对路径/linux符号链接检查
  10. 《MLB棒球创造营》:走近棒球运动·纽约大都会队
  11. Cygwin 安装使用
  12. html 怎么设置hr的颜色,html hr标签能设置黄颜色吗
  13. 【华为云服务器初体验】-关于华为云服务器
  14. 吉林大学数据库系统原理期末复习笔记
  15. 一个简单到令人发指的 ADRCI 工具操作方法
  16. SAS实验04 ——回归分析
  17. 肖秀荣:2022考研政治大纲解读及复习建议
  18. 掩膜裁剪tif步骤_ENVI中掩膜掩膜操作及影像分类教程(转)
  19. 当前中国计算机硬件发展情况,中国计算机硬件技术发展与展望.doc
  20. linux常用命令-修改主机名

热门文章

  1. 第十二章 类和动态内存分配
  2. spring AOP解析之xml方式详解
  3. 10种CSS3实现的Loading效果
  4. 四条命令搞定mysql主从
  5. 预留创建时检查增强点:nbsp;MB_RE…
  6. Python之深入解析一行代码计算每个省面积的神器Geopandas
  7. HarmonyOS之常用布局StackLayout的使用
  8. 彻底掌握动态规划,第一节
  9. PAT (Basic Level) Practice (中文)1001 害死人不偿命的(3n+1)猜想 (15 分)
  10. Java-OpenCV(一)准备工作