BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案
Description
Farmer John is constructing a new milking machine and wishes to keep it secret as long as possible. He has hidden in it deep within his farm and needs to be able to get to the machine without being detected. He must make a total of T (1 <= T <= 200) trips to the machine during its construction. He has a secret tunnel that he uses only for the return trips. The farm comprises N (2 <= N <= 200) landmarks (numbered 1..N) connected by P (1 <= P <= 40,000) bidirectional trails (numbered 1..P) and with a positive length that does not exceed 1,000,000. Multiple trails might join a pair of landmarks. To minimize his chances of detection, FJ knows he cannot use any trail on the farm more than once and that he should try to use the shortest trails. Help FJ get from the barn (landmark 1) to the secret milking machine (landmark N) a total of T times. Find the minimum possible length of the longest single trail that he will have to use, subject to the constraint that he use no trail more than once. (Note well: The goal is to minimize the length of the longest trail, not the sum of the trail lengths.) It is guaranteed that FJ can make all T trips without reusing a trail.
Input
* Line 1: Three space-separated integers: N, P, and T * Lines 2..P+1: Line i+1 contains three space-separated integers, A_i, B_i, and L_i, indicating that a trail connects landmark A_i to landmark B_i with length L_i.
Output
* Line 1: A single integer that is the minimum possible length of the longest segment of Farmer John's route.
可以二分这个最长长度的上限 $mid$,每次只加入长度小于等于 $mid$ 的边
剩下的问题就是要找到 $T$ 个互不重叠的 '环'
跑一个最大流就好了,若流量大于等于 $T$,则符合要求
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 100000
#define inf 230
using namespace std;
int n,m,cc,S,T;
struct Dinic {
struct Edge {
int from,to,cap;
Edge(int from=0,int to=0,int cap=0):from(from),to(to),cap(cap){}
};
queue<int>Q;
vector<Edge>edges;
vector<int>G[300];
int current[300],d[300],vis[300];
void addedge(int u,int v,int c) {
edges.push_back(Edge(u,v,c));
edges.push_back(Edge(v,u,0));
int o=edges.size();
G[u].push_back(o-2);
G[v].push_back(o-1);
}
int BFS() {
memset(vis,0,sizeof(vis)), memset(d,0,sizeof(d));
vis[S]=1,d[S]=0;
Q.push(S);
while(!Q.empty()) {
int u=Q.front(); Q.pop();
for(int i=0;i<G[u].size();++i) {
Edge e=edges[G[u][i]];
if(e.cap>0 && !vis[e.to]) {
vis[e.to]=1, d[e.to]=d[u]+1;
Q.push(e.to);
}
}
}
return vis[T];
}
int dfs(int x,int cur) {
if(x==T) return cur;
int f,flow=0;
for(int i=current[x];i<G[x].size();++i) {
current[x]=i;
Edge e=edges[G[x][i]];
if(d[e.to]==d[x]+1 && e.cap > 0) {
f=dfs(e.to,min(cur, e.cap));
if(f) {
cur-=f, flow+=f, edges[G[x][i]].cap-=f, edges[G[x][i]^1].cap+=f;
if(cur<=0) return flow;
}
}
}
return flow;
}
int maxflow() {
int re=0;
while(BFS()) memset(current,0,sizeof(current)),re+=dfs(S,inf);
return re;
}
void re() {
edges.clear();
for(int i=0;i<300;++i) G[i].clear();
}
}net;
struct Node {
int u,v,c;
}nd[maxn];
bool cmp(Node a,Node b) {
return a.c < b.c;
}
int check(int t) {
net.re();
for(int i=1;i<=t;++i) {
net.addedge(nd[i].u,nd[i].v,1);
net.addedge(nd[i].v,nd[i].u,1);
}
return net.maxflow() >= cc;
}
int main() {
// setIO("input");
scanf("%d%d%d",&n,&m,&cc);
for(int i=1;i<=m;++i) scanf("%d%d%d",&nd[i].u,&nd[i].v,&nd[i].c);
sort(nd+1,nd+1+m,cmp);
int l=1,r=m,mid,ans=0;
S=1,T=n;
while(l<=r) {
mid=(l+r)>>1;
if(check(mid)) ans=mid, r=mid-1;
else l=mid+1;
}
printf("%d\n",nd[ans].c);
return 0;
}
BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案的更多相关文章
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...
- [bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流
[Usaco2005 feb]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 ...
- [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】
题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...
- BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
n<=200个点m<=40000条边无向图,求 t次走不经过同条边的路径从1到n的经过的边的最大值 的最小值. 最大值最小--二分,t次不重边路径--边权1的最大流. #inclu ...
- POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9658 Accepted: ...
- POJ2455 Secret Milking Machine
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12324 Accepted ...
- POJ 2455 Secret Milking Machine(最大流+二分)
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
随机推荐
- VMware克隆虚拟机后mac地址重新设置
ifconfig eth1 确定新网卡的MAC地址. nmcli con 确定新网卡的UUID vim /etc/udev/rules.d/70-persistent-net.rules 把原et ...
- Java多线程学习——知识点积累
开启多线程时,每一个线程都拥有自己的工作空间,每个工作空间都单独的和主存打交道. 并发的概念:多个线程同时操作同一个对象 当产生并发时,如果从工作空间写入数据到内存的线程时间片用完了,其他线程再从主存 ...
- 【Qt开发】V4L2 API详解 Camera详细设置
Camera的可设置项极多,V4L2 支持了不少.但Sam之前对这些设置的用法和涵义都是在看videodev2.h中边看边理解,感觉非常生涩.直到写这篇blog时,才发现v4l2有专门的SPEC来说明 ...
- 【Linux 源码】Linux源码比较重要的目录
(1)arch arch是architecture的缩写.内核所支持的每一种CPU体系,该目录下都有对应的子目录. 每个CPU的子目录,又进一步分解为boot.mm.kernel等子目录,分别包含控制 ...
- 浅拷贝&深拷贝
浅拷贝新的对象指向原来对象的地址 深拷贝新的对象中,原来是可变对象,会新复制一份值指向新的地址[11,22,33]若原来的对象里含有可变对象,里面的这个可变对象也会指向新的地址['qwer', 123 ...
- Kubernetes服务部署解决方案
学习了K8S的基础知识,我们的目的就是解决我们服务的迁移,那么接下去通过几个案例来感受一下K8s部署带来的便捷与效率. 环境准备: 3个节点,然后我这边也安装了 Ingress. 部署wordpres ...
- 思维体操: HDU1049Climbing Worm
Climbing Worm Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- asp.net后台cs中的JSON格式变量在前台Js中调用方法
//后台cs代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- Qt读写Json
Qt操作Json 1.QJsonDocument 1.详细说明 QJsonDocument类提供了读写JSON文档的方法. QJsonDocument是一个封装了完整JSON文档的类,可以从基于UTF ...
- 在Python中使用protobuf2.6.1 string format utf-8 and unicode error
版本信息: protobuf: v2.6.1 python: 2.7 关于在Python中使用protobuf时 string格式字段的编码问题 在python中编码格式多采用utf-8格式.而pro ...