#include "stdio.h" //poj 1459 最大流#include "string.h"#include "queue"using namespace std;#define N 205#define INF 0x3fffffffint n;bool mark;int map[N][N],maxf[N],route[N];int EK();int BFS();void init();int MIN(int x,int y);int main(){ int i,j; char ch; int m,np,nc; int u,v,w; while(scanf("%d%d%d%d",&n,&np,&nc,&m)!=-1) { init(); while(m--) { scanf(" (%d,%d)%d",&u,&v,&w); if(u==v) continue; map[u+1][v+1] += w; } int start = 0; //超级源点 while(np--) { scanf(" (%d)%d",&v,&w); map[start][v+1] += w; } int end = n+1; //超级汇点 while(nc--) { scanf(" (%d)%d",&u,&w); map[u+1][end] += w; } int ans = EK(); printf("%d\n",ans); } return 0;}void init(){ memset(map,0,sizeof(map)); }int MIN(int x,int y) { return x
q; route[0] = 0; q.push(0); while(!q.empty()) { x = q.front(); q.pop(); for(y=0;y<=n+1;y++) { if(route[y]==-1 && map[x][y]!=0) { maxf[y] = MIN(maxf[x],map[x][y]); route[y] = x; q.push(y); } } } if(route[n+1]==-1) return 0; return maxf[n+1];}