题目链接: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. oracle4

    分页查询 按雇员的id号升序取出 oracle的分页一共有三种方式 .根据rowid来分   ) ) order by cid desc; 执行时间0.03秒 .按分析函数来分   and rk> ...

  2. TCP keepalive under Linux

    TCP Keepalive HOWTO Prev   Next 3. Using TCP keepalive under Linux Linux has built-in support for ke ...

  3. lua wireshark 数据报解析

    http://www.360doc.com/content/13/1226/15/15257968_340284574.shtml http://www.360doc.com/userhome.asp ...

  4. hadoop错误org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2

    错误: org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException: Spill failed 错 ...

  5. sybase SA密码重置

    sa 密码忘记解决之道: su - sybase cd ASE/install vi RUN_etoh2 在文件的末尾加入 -psa \ 停止原数据库服务 由于密码遗忘,所以只能通过kill进程停止服 ...

  6. C#入门教程(三)–接收用户输入、转义字符、类型转换-打造C#入门教程

    上次教程主要讲解了visual stdio快捷键.变量相关的知识.具体教程戳这里:http://www.chengxiaoxiao.com/net/1027.html 越来越深入去写教程越来越发现,自 ...

  7. C#开发的进化史

    1.数据类型的进化 C#1中实现Product类型代码 public class Product { string name; public string Name { get { return na ...

  8. Gym 100187M-Heaviside Function

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

  9. Actioncontext跟ServletActionContext的区别---未完待续

    //public class BaseAction extends ActionSupport{ public static HttpServletRequest getRequest(){ retu ...

  10. js - 在拼接字符串中动态submit当前form

    今天在做一个项目的时候, mapabc中的inforWindow中,如果是超链接a,不直接响应. 后来的解决方案是动态产生form,并调用summit方法.如下 自定义一个js函数: function ...