POJ 1459 Power Network

6人阅读 评论(0) 收藏 举报
分类:
Power Network
Time Limit: 2000MS Memory Limit: 32768K
Total Submissions:29883 Accepted: 15466

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

Hint

The sample input contains two data sets. The first data set encodes a network with 2 nodes, power station 0 with pmax(0)=15 and consumer 1 with cmax(1)=20, and 2 power transport lines with lmax(0,1)=20 and lmax(1,0)=10. The maximum value of Con is 15. The second data set encodes the network from figure 1.

超级源和超级目的地


#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

const int MAX_D=200+5;
const int MAX_B=10200+5;
const int INF=1e9;

int tot;

int head[MAX_D];
int iter[MAX_D];
int level[MAX_D];
struct node{
    int to;
    int cap;
    int rev;
    int next;
};
node edge[2*MAX_B];


void add_edge(int a,int b,int c){

    edge[tot].to=b;
    edge[tot].cap=c;
    edge[tot].rev=tot+1;
    edge[tot].next=head[a];
    head[a]=tot++;

    edge[tot].to=a;
    edge[tot].cap=0;
    edge[tot].rev=tot-1;
    edge[tot].next=head[b];
    head[b]=tot++;

}


void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        for(int i=head[v];i!=0;i=edge[i].next){
            node &e=edge[i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    for(int &i=iter[v];i!=0;i=edge[i].next){
        node &e = edge[i];
        if(e.cap>0&&level[v]<level[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                edge[e.rev].cap+=d;
                return d;
            }
        }
    }

    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(1){
        bfs(s);
        if(level[t]<0)return flow;
        for(int i=0;i<MAX_D;i++){
            iter[i]=head[i];
        }
        int f;
        while((f=dfs(s,t,INF))>0){
            flow+=f;
        }
    }
}


void solve(){
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
        tot=1;
        memset(head,0,sizeof(head));
        while(d--){
            int x,y,z;
            scanf("  (%d,%d)%d",&x,&y,&z);
            add_edge(x+5,y+5,z);
        }

        while(b--){
            int x,y;
            scanf(" (%d)%d",&x,&y);
            add_edge(1,x+5,y);
        }
        while(c--){
            int x,y;
            scanf(" (%d)%d",&x,&y);
            add_edge(x+5,2,y);
        }
        printf("%d\n",max_flow(1,2));
    }


}

int main()
{
    solve();

    return 0;
}

查看评论

poj1459 - Power Network

想看更多的解题报告:http://blog.csdn.net/wangjian8006/article/details/7870410                                ...
  • wangjian8006
  • wangjian8006
  • 2012-08-29 13:39:40
  • 2235

POJ 1459 Power Network(最大流)

POJ 1459 Power Network(最大流) http://poj.org/problem?id=1459 题意:        (原题描述的过于复杂,原题中的s[i]根本不用管)总共有n个...
  • u013480600
  • u013480600
  • 2014-08-29 10:27:13
  • 665

poj1459 Power Network (最大流)

题意: 一个电力网络,一共n个节点,m条边,np个发电站,nc个用户。 每条边有一个容量,每个发电站有一个最大负载,每一个用户也有一个最大接受量。 问最多能供给多少电力。 思路: 多源多汇的...
  • u011265346
  • u011265346
  • 2015-01-13 19:49:28
  • 508

POJ-1459 Power Network

题目大意: 这道题目意思不好理解(可能只是我理解太差...) 一个电网,里面有一些结点,代表电站,消费者,调度站。电站不消耗电能,消费者不产生电能,调度站产生的电能和消耗的电能均为0 现在给出一...
  • Snow_Me
  • Snow_Me
  • 2016-08-08 22:24:43
  • 233

【网络流之最大流】POJ1459-Power Network【EK模板题】

题目链接:http://poj.org/problem?id=1459 好吧,其实就是一道模板题。。。 但是写的那么长的鸟语。。。orz...各种揣度题目意思。。。。 造福一下大家,我把题目数据的意思...
  • wlxsq
  • wlxsq
  • 2015-08-30 16:18:21
  • 772

POJ 1459 Power Network

Power Network Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi...
  • yeguxin
  • yeguxin
  • 2014-08-21 21:22:17
  • 237

POJ 1459 Power Network

题意:我就直接给出题目要求的东西吧: 在一个网络图中有n个点,其中有np个发电站,nc个用户,m条电线;每个发电站,用户,和电线都对应有一个最大的电流;让求出该网络中最大的电流; 添加一个...
  • u012313382
  • u012313382
  • 2014-07-28 17:04:00
  • 670

POJ 1459 —— Power Network

原题:http://poj.org/problem?id=1459 题意:一共有n个结点,在这些结点中有 np 个是发电站,有 nc 个是用户,给出m条线路所能运输的电量,以及每个发电站输出...
  • L_avender
  • L_avender
  • 2016-04-26 21:19:21
  • 138

poj(1459)Power Network

解题思路: 多源多汇最大流问 题目给出很多都是废话,特别是符号s(u),d(u),Con还有那条公式都别管,混淆视听 难点在于构图 电站p(u)均为源点,用户c(u)均为汇点,中转站当普通点处...
  • u011519618
  • u011519618
  • 2013-08-06 22:41:23
  • 380

Poj 1459 Power Network

题意:给几个发电站,给几个消耗站,再给几个转发点。发电站只发电,消耗站只消耗电,转发点只是转发电,给出各个传送线的传电能力,求消耗站能获得的最多电是多少。 思路:增加一个超级源点,和超级汇点,转...
  • Detective_Xin
  • Detective_Xin
  • 2012-01-15 18:49:35
  • 249
    个人资料
    持之以恒
    等级:
    访问量: 1426
    积分: 682
    排名: 7万+
    文章存档
    最新评论