前言

网络流的练习为什么我又排在最后啊!!!

Solution

我们先来挖掘一个式子:
\[
ab+cd>ad+bc(a<c,b<d)
\]
这个的证明很显然对吧。
然后就考虑最优策略一定是让最大的边和最大的流量搞在一起。
但是发现最大的流量我们不能够确定啊。
所以就是二分答案?
每一次重新建一个图然后跑Dinic即可。
辣鸡聊天鬼才,毁我青春。

代码实现

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
const int N=10010,M=100010;
double Inf=1e9+10;
int n,m,s,t,U[M],V[M];double Val[M],flow;
class Graph{
private:
    int front[N],nxt[M<<1],to[M<<1],cnt,dep[N],cur[N];
    double w[M<<1];
    bool bfs(){
        queue<int >Q;while(!Q.empty())Q.pop();
        memset(dep,0,sizeof(dep));
        Q.push(s);dep[s]=1;
        while(!Q.empty()){
            int u=Q.front();Q.pop();
            for(int i=front[u];i!=-1;i=nxt[i]){
                int v=to[i];
                if(!dep[v] && w[i]>=1e-10){
                    dep[v]=dep[u]+1;Q.push(v);
                }
            }
        }
        return dep[t];
    }
    double dfs(int u,double Flow){
        if(u==t || !Flow)return Flow;
        for(int &i=cur[u];i!=-1;i=nxt[i]){
            int v=to[i];
            if(dep[v]==dep[u]+1 && w[i]>=1e-10){
                double di=dfs(v,min(Flow,w[i]));
                if(di>=1e-10){
                    w[i]-=di;w[i^1]+=di;
                    return di;
                }
            }
        }
        return 0;
    }
public:
    void Add(int u,int v,double val){to[cnt]=v;nxt[cnt]=front[u];front[u]=cnt;w[cnt]=val;cnt++;}
    void init(){memset(front,-1,sizeof(front));cnt=0;}
    void Dinic(){
        while(bfs()){
            for(int i=1;i<=n;i++)cur[i]=front[i];
            double d=dfs(s,Inf);
            do{
                if(d<1e-10)break;
                flow+=d;
            }while(d=dfs(s,Inf));
        }
    }
}MaxFlow;
void build(double qaq){
    MaxFlow.init();
    for(int i=1;i<=m;i++){
        MaxFlow.Add(U[i],V[i],min(qaq,Val[i]));MaxFlow.Add(V[i],U[i],0);
    }
}
int main(){
    n=gi();m=gi();s=1;t=n;int p=gi();
    MaxFlow.init();
    for(int i=1;i<=m;i++){
        int u=gi(),v=gi(),val=gi();
        MaxFlow.Add(u,v,val);MaxFlow.Add(v,u,0);
        U[i]=u;V[i]=v;Val[i]=val;
    }
    MaxFlow.Dinic();
    printf("%.0lf\n",flow);double now=flow;
    double l=0,r=(double)flow+10,ans=0;
    while(r-l>=1e-10){
        double mid=(l+r)/2;
        build(mid);
        flow=0;
        MaxFlow.Dinic();
        if(now-flow<=1e-10)r=mid,ans=mid;
        else l=mid;
    }
    printf("%.4lf\n",ans*p);
    return 0;
}

[Sdoi2013]费用流(最大流,二分答案)的更多相关文章

  1. 【Luogu】P3705新生舞会(费用流+分数规划+二分答案)

    题目链接 本来以为自己可以做出来,结果……打脸了 (貌似来wc立了好几个flag了,都没竖起来) 不过乱蒙能蒙出一个叫“分数规划”的东西的式子还是很开心的 观察$C=\frac{a_{1}+a_{2} ...

  2. poj2391 最大流+拆点+二分答案+Floyd

    Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19553   Accepted: 4 ...

  3. BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 960  Solved: 5 ...

  4. bzoj 3597 [Scoi2014] 方伯伯运椰子 - 费用流 - 二分答案

    题目传送门 传送门 题目大意 给定一个费用流,每条边有一个初始流量$c_i$和单位流量费用$d_i$,增加一条边的1单位的流量需要花费$b_i$的代价而减少一条边的1单位的流量需要花费$a_i$的代价 ...

  5. BZOJ 3130: [Sdoi2013]费用流 网络流+二分

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1230  Solved: ...

  6. bzoj千题计划133:bzoj3130: [Sdoi2013]费用流

    http://www.lydsy.com/JudgeOnline/problem.php?id=3130 第一问就是个最大流 第二问: Bob希望总费用尽量大,那肯定是把所有的花费加到流量最大的那一条 ...

  7. Gym - 101908G 二分答案+最大流

    After the end of the truck drivers' strike, you and the rest of Nlogônia logistics specialists now h ...

  8. P3305 [SDOI2013]费用流

    题目描述 Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量. 一个合法的网络流方案必须满足: ...

  9. luogu P3305 [SDOI2013]费用流

    题目链接 bz似乎挂了... luogu P3305 [SDOI2013]费用流 题解 dalao告诉我,这题 似乎很水.... 懂了题目大意就可以随便切了 问1,最大流 问2,二分最大边权求,che ...

随机推荐

  1. js jquery 取得周月年时间

    function formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth() + 1; var ...

  2. UGUI控制UI的显示层级

    1.调用transform.SetAsLastSibling();将该UI的显示层级调到最上面. 调用transform.SetAsFirstSibling();将该UI的显示层级调到最下面. 2. ...

  3. 821. Shortest Distance to a Character

    class Solution { public: vector<int> shortestToChar(string S, char C) { int len=S.length(); ve ...

  4. 674. Longest Continuous Increasing Subsequence

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  5. 【fiddler】抓取https数据失败,全部显示“Tunnel to......443”

    这个问题是昨天下午就一直存在的,知道今天上午才解决,很感谢“韬光养晦”. 问题描述:  按照网络上的教程,设置fiddler开启解密https的选项,同时fiddler的证书也是安装到系统中,但是抓取 ...

  6. mysql学习之路_高级数据操作

    关系 将实体与实体的关系,反应到最终数据表的设计上来,将关系分为三种,一对多,多对多,多对多. 所有关系都是表与表之间的关系. 一对一: 一张表的一条记录一定只对应另外一张表的一条记录,反之亦然. 例 ...

  7. BZOJ 1029 [JSOI2007]建筑抢修 (贪心 + 优先队列)

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 5452  Solved: 2422[Submit][Statu ...

  8. Redis和RabbitMQ在项目中的使用

    一:Redis的使用 1.先引入pom.xml的依赖 <dependency> <groupId>redis.clients</groupId> <artif ...

  9. WinSockets编程(六)select模式

    select模式的思想 创建FD_SET fd_all,并初始化FD_ZERO(&fd_all); Step1  初始时: Step2   加入一个套接字之后,比如FD_SET(sServer ...

  10. SED单行脚本快速参考(Unix 流编辑器)

    ------------------------------------------------------------------------- SED单行脚本快速参考(Unix 流编辑器) 200 ...