锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Description Input Output Sample Input Sample Output Hint Source 鍏蜂綋鐪嬬▼搴忓惂錛屼笉瑙i噴.
Time Limit: 2000MS
Memory Limit: 32768K
Total Submissions: 15399
Accepted: 8201

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. 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
15
6
棰樼洰閾炬帴:http://poj.org/problem?id=1459
writed by kuangbin
杞澆璇鋒敞鏄庡嚭澶?/strong>
/*
POJ 1459
*/
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN=110;
const int INF=0x7fffffff;
int map[MAXN][MAXN],path[MAXN],flow[MAXN],start,end;
int n;//鐐圭殑涓暟
queue<int>q;
int bfs()
{
int i,t;
while(!q.empty()) q.pop();//娓呯┖闃熷垪
memset(path,-1,sizeof(path));
path[start]=0;
flow[start]=INF;
q.push(start);
while(!q.empty())
{
t=q.front();
q.pop();
if(t==end) break;
for(i=0;i<=n;i++)
{
if(i!=start&&path[i]==-1&&map[t][i])
{
flow[i]=flow[t]<map[t][i]?flow[t]:map[t][i];
q.push(i);
path[i]=t;
}
}
}
if(path[end]==-1) return -1;
return flow[n];
}
int Edmonds_Karp()
{
int max_flow=0,step,now,pre;
while((step=bfs())!=-1)
{
max_flow+=step;
now=end;
while(now!=start)
{
pre=path[now];
map[pre][now]-=step;
map[now][pre]+=step;
now=pre;
}
}
return max_flow;
}
int main()
{
int i,u,v,z,np,nc,m;
while(scanf("%d%d%d%d",&n,&np,&nc,&m)!=EOF)
{
memset(map,0,sizeof(map));
while(m--)
{
while(getchar()!='(');
scanf("%d,%d)%d",&u,&v,&z);
u++;v++;
map[u][v]=z;
}
while(np--)
{
while(getchar()!='(');
scanf("%d)%d",&u,&z);
u++;
map[0][u]=z;
}
while(nc--)
{
while(getchar()!='(');
scanf("%d)%d",&u,&z);
u++;
map[u][n+1]=z;
}
n++;
start=0;end=n;
printf("%d\n",Edmonds_Karp());
}
return 0;
}
]]>