#include<stdio.h>

#include<queue>

#include<string.h>

using namespace std;

#define inf 0x7fffffff

#define N 300

int p,t,n;

int Min(int a,int b) {

return a>b?b:a;

}

struct node {

   int u,v,w,f;

}mp[40001];

int flow[N][N],d[N];

int bfs() {

 int cur,i;

 queue<int>q;

 memset(d,0,sizeof(d));

 d[1]=1;

   q.push(1);

    while(!q.empty()) {

        cur=q.front();

        q.pop();

        for(i=1;i<=n;i++)

     if(flow[cur][i]&&!d[i]) {

          d[i]=d[cur]+1;

          if(i==n)

            return 1;

           q.push(i);

     }

    }

    return 0;

}

int dfs(int u,int limit) {

    if(u==n)

        return limit;

  int cost=0,i,k;

 for(i=1;i<=n;i++)

    if(d[i]==d[u]+1&&flow[u][i]) {

        k=dfs(i,Min(limit-cost,flow[u][i]));

        if(k>0) {

            flow[u][i]-=k;

            flow[i][u]+=k;

            cost+=k;

            if(cost==limit)

                break;

        }

        else

            d[i]=-1;

    }

    return cost;

}

int dinic (int mid) {

   int ans=0,i;

    memset(flow,0,sizeof(flow));

  for(i=1;i<=p;i++)

    if(mp[i].w<=mid) {

   flow[mp[i].u][mp[i].v]++;

   flow[mp[i].v][mp[i].u]++;

    }

   while(bfs())

    ans+=dfs(1,inf);

     if(ans>=t)

        return 1;

     return 0;

}

int main() {

      int i,min,max,mid;

      while(scanf("%d%d%d",&n,&p,&t)!=EOF) {

            min=inf;

      max=-1;

         for(i=1;i<=p;i++) {

            scanf("%d%d%d",&mp[i].u,&mp[i].v,&mp[i].w);

            if(mp[i].w>max)

                max=mp[i].w;

            if(mp[i].w<min)

                min=mp[i].w;

         }

          while(min<=max) {

            mid=(min+max)/2;

            if(dinic(mid))

                max=mid-1;

            else

                min=mid+1;

          }

          printf("%d\n",min);

      }

return 0;

}

nyoj 310二分+dinic的更多相关文章

  1. poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap

    poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...

  2. POJ2391 Floyd+离散化+二分+DINIC

    题意:       有n个猪圈,每个猪圈里面都有一定数量的猪(可能大于当前猪圈的数量),每个猪圈都有自己的容量,猪圈与猪圈之间给出了距离,然后突然下雨了,问多久之后所有的猪都能进圈. 思路:     ...

  3. Optimal Milking(POJ2112+二分+Dinic)

    题目链接:http://poj.org/problem?id=2112 题目: 题意:有k台挤奶机,c头奶牛,每台挤奶机每天最多生产m的奶,给你每个物品到其他物品的距离(除了物品到自己本省的距离为0外 ...

  4. POJ 3189 二分+Dinic

    题意: 思路: 二分跨度 枚举最低座次 建图:源点向每头牛连边权为1的边 每头牛向当前枚举的B的区间这段连上边权为1的边 所有座次向汇点连边权为牛棚容量的边 判判流量是不是等于n 一开始写得是直接枚举 ...

  5. nyoj-310-河南省第四届省赛题目-二分+dinic

    SECRET 时间限制:3000 ms  |  内存限制:65535 KB 难度:6   描述 Dr.Kong is constructing a new machine and wishes to ...

  6. nyoj 306 二分+dfs

    #include<stdio.h> #include<string.h> #define N 200 int Min(int a,int b) { return a>b? ...

  7. JSOI2018R2题解

    D1T1:潜入行动 裸的树上DP.f[i][j][0/1][0/1]表示以i为根的子树放j个设备,根有没有放,根有没有被子树监听,的方案数.转移显然. #include<cstdio> # ...

  8. 2019 wannafly winter camp day5-8代码库

    目录 day5 5H div2 Nested Tree (树形dp) 5F div2 Kropki (状压dp) 5J div1 Special Judge (计算几何) 5I div1 Sortin ...

  9. poj 2112 floyd+Dinic最大流+二分最小值

    题目大意是: K台挤奶机器,C头牛,K不超过30,C不超过200,每台挤奶机器最多可以为M台牛工作,给出这些牛和机器之间,牛和牛之间,机器与机器之间的距离,在保证让最多的牛都有机器挤奶的情况下,给出其 ...

随机推荐

  1. Finding Nemo(搜索)

    http://poj.org/problem?id=2049 题意:有一个迷宫,迷宫中有墙.门和空地.有M道墙,每一道墙用(x,y,d,t)表示,(x,y)表示墙的起始坐标,(d=1,t)表示向上t个 ...

  2. [Swift通天遁地]七、数据与安全-(9)文件的压缩和解压

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. vue打包问题:Tip: built files are meant to be served over an HTTP server.

    npm run build之后,出现提示:Tip: built files are meant to be served over an HTTP server. Opening index.html ...

  4. 面向对象之继承-5种JavaScript继承的方法

    今天我们讨论一下常用的几种继承方法:首先我们创建一个动物函数Animal: function Animal () { this.species = '动物' }再写准备名叫猫咪的函数Cat: func ...

  5. 利用python去除红章

    近期接的一个需求需要去除图片的红章,用到了PIL库. from PIL import Image,ImageEnhanceimport os#f="5-12 - 0001.tif" ...

  6. Http协议详解(转)>>>写的很好

    声明:本片文章非原创,仅供自己学习并分享 内容来源于博客园作者MIN飞翔的HTTP协议详解地址http://www.cnblogs.com/EricaMIN1987_IT/p/3837436.html ...

  7. [转]Linux命令之iconv

    转自:http://lorna8023.blog.51cto.com/777608/420313 用途说明 iconv命令是用来转换文件的编码方式的(Convert encoding of given ...

  8. 1、Xamarin 环境准备

    一.安装环境 1.安装VS2017 2.安装Xamarin扩展包 3.安装NDK 工具栏中,一个为AVD(模拟器管理)一个为NDK(管理Andoid SDK) 3.1 先打开NDK,在Tools\Op ...

  9. [转][IPC通信]基于管道的popen和pclose函数

    标准I/O函数库提供了popen函数,它启动另外一个进程去执行一个shell命令行. 这里我们称调用popen的进程为父进程,由popen启动的进程称为子进程. popen函数还创建一个管道用于父子进 ...

  10. 清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具

    https://gitee.com/bitprince/memory 1. 概述 1.1 连接.语句和结果集 从JDBC的规范上看,其对数据访问层有相当简洁的抽象:1.连接(connection) 2 ...