http://poj.org/problem?id=2455 (题目链接)

题意

  给出一张n个点,p条边的无向图,需要从1号节点走到n号节点一共T次,每条边只能经过1次,问T次经过的最大的边最小是多少。

Solution

  很显然,二分答案,然后建图跑最大流即可。

细节

  双向边?

代码

// poj2455
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=300,maxm=40010;
struct edge {int to,next,w;}e[maxm<<1];
int head[maxn],d[maxn];
int cnt,n,p,T,u[maxm],v[maxm],w[maxm],ans; void link(int u,int v,int w) {
e[++cnt]=(edge){v,head[u],w};head[u]=cnt;
e[++cnt]=(edge){u,head[v],w};head[v]=cnt;
}
void build(int k) {
cnt=1;
memset(head,0,sizeof(head));
for (int i=1;i<=p;i++)
if (w[i]<=k) link(u[i],v[i],1);
}
bool bfs() {
memset(d,-1,sizeof(d));
queue<int> q;q.push(1);d[1]=0;
while (!q.empty()) {
int x=q.front();q.pop();
for (int i=head[x];i;i=e[i].next) if (e[i].w && d[e[i].to]<0) {
d[e[i].to]=d[x]+1;
q.push(e[i].to);
}
}
return d[n]>0;
}
int dfs(int x,int f) {
if (x==n || f==0) return f;
int used=0,w;
for (int i=head[x];i;i=e[i].next) if (e[i].w && d[e[i].to]==d[x]+1) {
w=dfs(e[i].to,min(e[i].w,f-used));
used+=w;
e[i].w-=w;e[i^1].w+=w;
if (used==f) return used;
}
if (!used) d[x]=-1;
return used;
}
void Dinic() {
while (bfs()) ans+=dfs(1,inf);
}
int main() {
scanf("%d%d%d",&n,&p,&T);
int L=inf,R=0;
for (int i=1;i<=p;i++)
scanf("%d%d%d",&u[i],&v[i],&w[i]),L=min(L,w[i]),R=max(R,w[i]);
int res=0;
while (L<=R) {
int mid=(L+R)>>1;
build(mid);ans=0;
Dinic();
if (ans>=T) res=mid,R=mid-1;
else L=mid+1;
}
printf("%d",res);
return 0;
}

  

【poj2455】 Secret Milking Machine的更多相关文章

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

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

  2. POJ2455 Secret Milking Machine

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12324   Accepted ...

  3. POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9658   Accepted: ...

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

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

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

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

  6. 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 ...

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

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

  8. 【USACO】Optimal Milking

    题目链接 :        [POJ]点击打开链接        [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...

  9. 【Trie】Secret Message 秘密信息

    [题目链接]: https://loj.ac/problem/10054 [题意] 我认为这个题目最难的是题意: 其实分了两种情况: 1.如果当前文本串匹配不完,那么答案的是:匹配过程中遇到的模式串结 ...

随机推荐

  1. Java的super调用案例: super.getClass()返回的是子类自己

    If you override a method from your superclass (or your superclass's superclass etc.), super.theMetho ...

  2. [转]考虑 PHP 5.0~5.6 各版本兼容性的 cURL 文件上传

    FROM : https://segmentfault.com/a/1190000000725185 最近做的一个需求,要通过PHP调用cURL,以multipart/form-data格式上传文件. ...

  3. Visual Studio 2012 cannot identify IHttpActionResult

    使用ASP.NET Web API构造基于restful风格web services,IHttpActionResult是一个很好的http结果返回接口. 然而发现在vs2012开发环境中,Syste ...

  4. Power of Two

    Given an integer, write a function to determine if it is a power of two. bool isPowerOfTwo(int n) { ...

  5. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  6. 我的第一个 JSP (SSH) 个人网站【开源】

    唠叨两句背景 相当长时间没上来发帖了,最近几个月除了完成产品经理一个又一个重复又重复的app开发任务之外,最大的工作莫过于充分利用上笔主的业余时间,系统性地跟李刚同志学习JavaEE的SSH框架开发技 ...

  7. lecture16-联合模型、分层坐标系、超参数优化及本课未来的探讨

    这是HInton的第16课,也是最后一课. 一.学习一个图像和标题的联合模型 在这部分,会介绍一些最近的在学习标题和描述图片的特征向量的联合模型上面的工作.在之前的lecture中,介绍了如何从图像中 ...

  8. 求连续最大子序列积 - leetcode. 152 Maximum Product Subarray

    题目链接:Maximum Product Subarray solutions同步在github 题目很简单,给一个数组,求一个连续的子数组,使得数组元素之积最大.这是求连续最大子序列和的加强版,我们 ...

  9. 4-pwd 打印当前工作目录

    pwd print name of current/working directory 打印当前工作目录 [语法]: pwd [选项] [参数] [功能介绍] pwd命令以绝对路径的方式显示用户当前工 ...

  10. Ubuntu下安装IDA pro

    预备 由于IDA pro只能装在32位环境下,如果是64位Ubuntu,需要运行如下命令安装32位的必备库. sudo dpkg --add-architecture i386 sudo apt-ge ...