这题想了好久,一直认为应该bfs更新后求最小值把发电站最大发电加进去,但是又发现这样求增广路的时候会导致用户更新出错,
加源点和汇点也考虑到了,没想到居然发电量就是超级源到源点的v,居然这么简单@。@
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=,inf=; int v[N][N],s,t,n;
int pre[N];
bool vis[N];
bool bfs()
{
memset(vis,,sizeof vis);
memset(pre,,sizeof pre);
vis[s]=;
queue<int>q;
q.push(s);
while(!q.empty()){
int x=q.front();
if(x==t)return ;
q.pop();
for(int i=;i<=n+;i++)
{
if(!vis[i]&&v[x][i])
{
vis[i]=;
q.push(i);
pre[i]=x;
}
}
}
return ;
}
int max_flow()
{
int ans=;
while(){
if(!bfs())return ans;
int minn=inf+;
for(int i=t;i!=s;i=pre[i])
minn=min(minn,v[pre[i]][i]);
for(int i=t;i!=s;i=pre[i])
{
v[pre[i]][i]-=minn;
v[i][pre[i]]+=minn;
}
ans+=minn;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int np,nc,m;
while(cin>>n>>np>>nc>>m){
memset(v,,sizeof v);
int a,b,c;
char ru;
while(m--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
cin>>ru;
cin>>c;
v[a][b]+=c;
}
while(np--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
v[n][a]=b;
}
while(nc--){
cin>>ru;
cin>>a;
cin>>ru;
cin>>b;
v[a][n+]=b;
}
s=n,t=n+;
cout<<max_flow()<<endl;
}
return ;
}