http://poj.org/problem?id=3308
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#define maxn 10000
using namespace std; const int inf=<<;
int n,m,l,x,y;
double c,f;
double cap[][],flow[][];
int p[];
double a[]; void EK(int s)
{
queue<int>q;
memset(flow,,sizeof(flow));
f=;
for(; ;)
{
memset(a,,sizeof(a));
memset(p,-,sizeof(p));
a[s]=inf;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v=; v<=m+n+; v++)
{
if(!a[v]&&cap[u][v]>flow[u][v])
{
p[v]=u;
q.push(v);
a[v]=min(a[u],cap[u][v]-flow[u][v]);
}
}
}
if(a[m+n+]==) break;
for(int u=m+n+; u!=; u=p[u])
{
flow[p[u]][u]+=a[m+n+];
flow[u][p[u]]-=a[m+n+];
}
f+=a[m+n+];
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(cap,,sizeof(cap));
scanf("%d%d%d",&m,&n,&l);
for(int i=;i<=m; i++)
{
scanf("%lf",&c);
cap[][i]=log(c);
}
for(int i=m+; i<=m+n; i++)
{
scanf("%lf",&c);
cap[i][m+n+]=log(c);
}
for(int i=; i<l; i++)
{
scanf("%d%d",&x,&y);
cap[x][m+y]=inf;
}
f=;
EK();
printf("%.4f\n",exp(f));
}
return ;
}