#include <stdio.h> #include <string.h> #include <math.h> #define MAX 110 #define INF 10000000 struct node { double c,f; }map[MAX][MAX]; int pre[MAX],queue[MAX]; int s,t; int bfs() { int i,cur,qs,qe; memset(pre,-1,sizeof(pre)); pre[s]=s; qs=0;qe=1; queue[qs]=s; while(qs<qe) { cur=queue[qs++]; for(i=0;i<=t;i++) { if(pre[i]==-1&&map[cur][i].c-map[cur][i].f>0) { queue[qe++]=i; pre[i]=cur; if(i==t)return 1; } } } return 0; } double maxflow() { double max=0,min; int i; while(bfs()) { min=INF; for(i=t;i!=s;i=pre[i]) if(map[pre[i]][i].c-map[pre[i]][i].f<min) min=map[pre[i]][i].c-map[pre[i]][i].f; for(i=t;i!=s;i=pre[i]) { map[pre[i]][i].f+=min; map[i][pre[i]].f-=min; } max+=min; } return max; } int main() { int i,j,n,m,l,r,cc,w; double c; scanf("%d",&w); while(w--) { memset(map,0,sizeof(map)); scanf("%d%d%d",&n,&m,&l); s=0;t=n+m+1; for(i=1;i<=n;i++) { scanf("%lf",&c); map[s][i].c=log(c); } for(i=1;i<=m;i++) { scanf("%lf",&c); map[i+n][t].c=log(c); } for(i=1;i<=l;i++) { scanf("%d%d",&r,&cc); map[r][n+cc].c=INF; } printf( "%.4lfn",exp( maxflow() ) ); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)