poj3308

边加错了。正反加为INF了。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<ull,int>::iterator IT;
const lon SZ=5900,SSZ=9000010,APB=3000010,mod=100000,one=97;
const lon INF=0x3f3f3f3f3f3f3f3f;
lon n,m,knum,S=5707,T=5708;
struct nd{
    lon to,wt;
    nd(lon a=0,lon b=0):to(a),wt(b){}
};
lon dep[SZ];
lon head[SZ],nex[SSZ],to[SSZ];
double wt[SSZ];
lon cnt=-1;

void add(lon u,lon v,double w)
{
    ++cnt;
    nex[cnt]=head[u];
    head[u]=cnt;
    to[cnt]=v,wt[cnt]=w;
}

bool bfs()
{
    memset(dep,0,sizeof(dep));
    queue<lon> q;
    q.push(S);
    dep[S]=1;
    for(;q.size();)
    {
        lon fr=q.front();
        q.pop();
        for(lon i=head[fr];i!=-1;i=nex[i])
        {
            lon t=to[i];
            double w=wt[i];
            if(w>EPS&&!dep[t])
            {
                dep[t]=dep[fr]+1;
                q.push(t);
            }
        }
    }
    return dep[T];
}

double dinic(lon x,double flow)
{
    if(x==T)return flow;
    else
    {
        double rem=flow;
            for(lon i=head[x];i!=-1&&rem>EPS;i=nex[i])
            {
                
                lon t=to[i];
                double w=wt[i];
                if(dep[t]!=dep[x]+1||w<EPS)continue;
                double tmp=dinic(t,min(rem,w));
                if(tmp<EPS)dep[t]=0;
                wt[i]-=tmp;
                wt[i^1]+=tmp;
                rem-=tmp;
            }
        return flow-rem;
    }
}

void init()
{
    cin>>n>>m>>knum;
    memset(head,-1,sizeof(head));
    cnt=-1;
    for(int i=1;i<=n;++i)
    {
        double tmp;
        cin>>tmp;
        add(S,i,log2(tmp));
        add(i,S,log2(tmp));
    }
    for(int i=1;i<=m;++i)
    {
        double tmp;
        cin>>tmp;
        //err;
        add(i+n,T,log2(tmp));
        add(T,i+n,log2(tmp));
    }
    for(int i=1;i<=knum;++i)
    {
        int a,b;
        cin>>a>>b;
        add(a,b+n,log2(INF));
        add(b+n,a,0);
    }
    double res=0;
    for(;bfs();res+=dinic(S,log2(INF)));
    cout<<fixed<<setprecision(4)<<pow(2,res)<<endl;
}

void work()
{
    
}

void release()
{    
    
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    cin>>casenum;
    //cout<<casenum<<endl;
    for(lon time=1;time<=casenum;++time)
    //for(lon time=1;cin>>n>>m>>S>>T,n;++time)
    {
        init();
        work();
        release();
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/gaudar/p/10904548.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值