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 ...
随机推荐
- Centos快速安装 Memcached
rpm qa|grep memcached //首先检查memcache是否已经安装完成 yum install memcached //(提示你是否确认安装输入y)检查完成后执行安装命令 yum i ...
- Python基础语法之列表 元组
1 列表 列表由一系列按照特定顺序的元素组成,其中的元素可以使不同的数据类型,用[ ]来表示列表,用逗号来分割列表中的元素. 1.1 列表操作之切片 a = [1, 2, 3, 4, 5, 6, 7, ...
- 20191127 Spring Boot官方文档学习(4.12)
4.12.缓存(Caching) Spring框架提供了对应用程序透明添加缓存的支持.从本质上讲,抽象将缓存应用于方法,从而根据缓存中可用的信息减少执行次数.缓存逻辑是透明应用的,不会对调用者造成任何 ...
- 删除MicrosoftOffice2016的扫尾工作
因为用到一些画流程图之类的工具,想到以前用的Visio挺好用的,就找来安装一下,结果因为装了Microsoft Office2016在安装时报错不断,先说下网上的帖子:用OfficeDeploymen ...
- [Web 前端] 029 jQuery 元素的“节操”
目录 jQuery 元素的节点操作 1. 创建节点 2. 插入节点 2.1 在现存元素的内部,从后面插入元素 2.2 在现存元素的内部,从前面插入元素 2.3 在现存元素的外部,从后面插入元素 2.4 ...
- Docker网络大揭秘(单机)
docker网络官网 https://docs.docker.com/network/ Docker容器和服务如此强大的原因之一是您可以将它们连接在一起,或将它们连接到非Docker工作负载.Dock ...
- Spark-Core RDD行动算子
1.reduce(func) 通过func函数聚集RDD 中的所有元素,先聚合分区内数据,再聚合分区间数据. scala> val rdd1 = sc.parallelize(1 to 100) ...
- NoSQL特点
- wordpress数据库结构以及数据表之间的关系
默认WordPress一共有以下11个表.这里加上了默认的表前缀 wp_ . wp_commentmeta:存储评论的元数据 wp_comments:存储评论 wp_links:存储友情链接(Blog ...
- windows安装nginx部署
转自:https://www.jb51.net/article/47066.htm 一.下载安装Nginx(本文环境为windows xp 32bit环境) 解压nginx-1.0.11.zip,进入 ...