【poj2455】 Secret Milking Machine
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的更多相关文章
- 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+网络流最大流
题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ...
- POJ2455 Secret Milking Machine
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12324 Accepted ...
- POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9658 Accepted: ...
- POJ 2455 Secret Milking Machine(最大流+二分)
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- [bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流
[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 题目大意:约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农 ...
- 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 ...
- POJ 2455 Secret Milking Machine (二分+无向图最大流)
[题意]n个点的一个无向图,在保证存在T条从1到n的不重复路径(任意一条边都不能重复)的前提下,要使得这t条路上经过的最长路径最短. 之所以把"经过的最长路径最短"划个重点是因为前 ...
- 【USACO】Optimal Milking
题目链接 : [POJ]点击打开链接 [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...
- 【Trie】Secret Message 秘密信息
[题目链接]: https://loj.ac/problem/10054 [题意] 我认为这个题目最难的是题意: 其实分了两种情况: 1.如果当前文本串匹配不完,那么答案的是:匹配过程中遇到的模式串结 ...
随机推荐
- 【MVC版本】MVC3、MVC4之MODEL验证大比拼
1.密码验证 MVC3 [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = &quo ...
- redis 学习笔记(3)-master/slave(主/从模式)
类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...
- Mybatis.Net 整合 ODP.NET Managed
初步接触MyBatis.Net的朋友,请先移步 MyBatis.Net 学习手记 1. 项目中先添加Oracle.ManagedDataAccess.dll程序集引用 2. MyBatis.Net 中 ...
- 【转】加快网站访问速度——Yslow极限优化
Yslow是一套雅虎的网页评分系统,详细的列出了各项影响网页载入速度的参数,这里不做多说. 我之前就一直参考Yslow做博客优化,经过长时间的学习也算是有所收获,小博的YslowV2分数达到了94分( ...
- 如何使用 UC浏览器开发者版 进行移动端调试
在 如何用 fiddler 代理调试本地手机页 一文中我们了解了如何用手机查看 PC 端写的网页(本地),但是我们只能看到页面效果,如果哪段 js 挂了,那部分样式失效了,我们该如何进行调试呢?今天为 ...
- ASP.NET MVC3入门教程之ajax交互
本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=100&extra=page%3D1 随着web技术的不断发展与 ...
- codevs 4543 treap 模板
type rec=record lc,rc,v,rnd,size,w,fa:longint; end; var n,root,tot,ans,opt,x,i,po:longint; tr:array[ ...
- JavaScript的理解记录(2)
一.表达式与运算符: 1.对于属性访问表达式: var arr = {first:"hh","second":"gg",third:null ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...