题目链接:BZOJ - 1733

题目分析

直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量。

代码

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; const int MaxN = 200 + 5, MaxM = 80000 + 5, INF = 999999999; inline int gmin(int a, int b) {return a < b ? a : b;}
inline int gmax(int a, int b) {return a > b ? a : b;} int n, m, Ts, Top, Ans, S, T, Tot;
int d[MaxN], Num[MaxN]; struct Edge
{
int u, v, w, len;
Edge *Next, *Other;
} E[MaxM * 2], *P = E, *Point[MaxN], *Last[MaxN], *EA[MaxM]; inline void AddEdge(int x, int y, int z)
{
Edge *Q = ++P; ++P; EA[++Top] = P;
P -> u = x; P -> v = y; P -> len = z;
P -> Next = Point[x]; Point[x] = P; P -> Other = Q;
Q -> u = y; Q -> v = x; Q -> len = z;
Q -> Next = Point[y]; Point[y] = Q; Q -> Other = P;
} void Set_Edge(int x)
{
for (int i = 1; i <= Top; ++i)
{
if (EA[i] -> len <= x) EA[i] -> w = 1;
else EA[i] -> w = 0;
EA[i] -> Other -> w = 0;
}
} int DFS(int Now, int Flow)
{
if (Now == T) return Flow;
int ret = 0;
for (Edge *j = Last[Now]; j; j = j -> Next)
if (j -> w && d[j -> u] == d[j -> v] + 1)
{
Last[Now] = j;
int p = DFS(j -> v, gmin(j -> w, Flow - ret));
j -> w -= p; j -> Other -> w += p; ret += p;
if (ret == Flow) return ret;
}
if (d[S] >= Tot) return ret;
if (--Num[d[Now]] == 0) d[S] = Tot;
++Num[++d[Now]];
Last[Now] = Point[Now];
return ret;
} bool Check()
{
int MaxFlow = 0;
S = 1; T = n; Tot = n;
memset(d, 0, sizeof(d));
memset(Num, 0, sizeof(Num)); Num[0] = Tot;
for (int i = 1; i <= Tot; ++i) Last[i] = Point[i];
while (d[S] < Tot) MaxFlow += DFS(S, INF);
if (MaxFlow >= Ts) return true;
else return false;
} int main()
{
scanf("%d%d%d", &n, &m, &Ts);
int a, b, c;
int l, r, mid;
l = INF; r = -INF;
Top = 0;
for (int i = 1; i <= m; ++i)
{
scanf("%d%d%d", &a, &b, &c);
AddEdge(a, b, c);
AddEdge(b, a, c);
l = gmin(l, c);
r = gmax(r, c);
}
while (l <= r)
{
mid = (l + r) >> 1;
Set_Edge(mid);
if (Check())
{
Ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
printf("%d\n", Ans);
return 0;
}

  

[BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】的更多相关文章

  1. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  2. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...

  3. [bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流

    [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 题目大意:约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农 ...

  4. 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+网络流最大流

    题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ...

  5. BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    n<=200个点m<=40000条边无向图,求   t次走不经过同条边的路径从1到n的经过的边的最大值   的最小值. 最大值最小--二分,t次不重边路径--边权1的最大流. #inclu ...

  6. poj 2455 Secret Milking Machine 二分+最大流 sap

    题目:p条路,连接n个节点,现在需要从节点1到节点n,不重复走过一条路且走t次,最小化这t次中连接两个节点最长的那条路的值. 分析:二分答案,对于<=二分的值的边建边,跑一次最大流即可. #in ...

  7. POJ 2455 Secret Milking Machine (二分 + 最大流)

    题目大意: 给出一张无向图,找出T条从1..N的路径,互不重复,求走过的所有边中的最大值最小是多少. 算法讨论: 首先最大值最小就提醒我们用二分,每次二分一个最大值,然后重新构图,把那些边权符合要求的 ...

  8. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  9. POJ 2455 Secret Milking Machine (二分+无向图最大流)

    [题意]n个点的一个无向图,在保证存在T条从1到n的不重复路径(任意一条边都不能重复)的前提下,要使得这t条路上经过的最长路径最短. 之所以把"经过的最长路径最短"划个重点是因为前 ...

随机推荐

  1. android 判断应用程序是否已安装

    1.判断是否安装/** check the app is installed*/private boolean isAppInstalled(Context context,String packag ...

  2. jvisualvm图解

    http://blog.csdn.net/a19881029/article/details/8432368 jvisualvm能干什么:监控内存泄露,跟踪垃圾回收,执行时内存.cpu分析,线程分析. ...

  3. Gym 100187M-Heaviside Function

    题意:给定函数: f(x) = θ(s1x - a1) + θ(s2x - a2) + ... + θ(snx - an), where si =  ± 1. Calculate its values ...

  4. 25、Javascript 事件

    Javascript 事件 是指 Javascript 捕获到用户的操作,并做出正确的相应. Javascript 事件一般与DOM元素绑定. Javascript处理事件的基本机制 1.对DOM元素 ...

  5. javascript 和 jquery 语法上的一些区别

    jQuery 能大大简化 Javascript 程序的编写,我最近花时间了解了一下 jQuery,把我上手过程中的笔记和大家分享出来,希望对大家有所帮助.要使用 jQuery,首先要在 HTML 代码 ...

  6. insert一句话实现插入一条数据并且返回这条数据的某列

    insert into [table] output inserted.columnName values();

  7. .NET下的加密解密大全(1): 哈希加密

    .NET有丰富的加密解密API库供我们使用,本博文总结了.NET下的Hash散列算法,并制作成简单的DEMO,希望能对大家有所帮助. MD5[csharp]using System; using Sy ...

  8. PhpStorm 注册码

    JetBrains PhpStorm key PhpStorm注册码 User Name :  EMBRACE  License Key : License Key : ===== LICENSE B ...

  9. Java的jLinqer包介绍

    1.介绍 熟悉C#的lambda 表达式,想要使用 LINQ 在 Java,是个问题,虽然 Java8用函数式接口已经实现了部分lambda 表达式,但是还是不够灵活. 2.Linqer简介 Linq ...

  10. 浅析MySQL中exists与in的使用 (写的非常好)

    转自http://sunxiaqw.blog.163.com/blog/static/990654382013430105130443/ exists对外表用loop逐条查询,每次查询都会查看exis ...