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 ...
随机推荐
- (转)Eclipse - CDT使用GDB调试C++的问题-无源文件命名(No source file named)
http://tech.ddvip.com/2014-09/1411618782213496.html Eclipse CDT调试C++, 使用的Unix的调试器GDB; 由于在Unix下, 文件的目 ...
- python winsound模块
(目标:出现交易下单.结束成交.数据中断等信号的时候,PC 发出声音提醒.) python winsound模块 winsound是Python的内置包,无需下载.可以直接通过 import wins ...
- FTP-学习笔记(1)
1.简单的SFTP.FTP文件上传下载 SftpTools.java package com.lfy.mian; import com.jcraft.jsch.*; import java.io.Fi ...
- Android的Monkey和MonkeyRunner
本文部分解释性语段摘自网络百科或其它BLOG,语句内容网络随处可见,也不知道谁是初始原创,便不再署名出处,如有雷同,还请见谅. Monkey 什么是Monkey Monkey是Android中的一个命 ...
- java基础笔记(9)
通过JDBC像数据库实现CRUD操作,这里通过一个存储查看人员的案例来了解java是如何通过JDBC实现与数据库的连接,三层结构中的模型层(数据访问),控制层(业务逻辑).以及视图层(表示层)又是怎么 ...
- “程序包com.sun.tools.javac.util不存在” 问题解决
最近工作中在编译打包项目的时候遇到了如标题所示的问题,报这个错误的类是 com.sun.tools.javac.util.Pair.问题很诡异,在Idea可以导入此类,项目启动运行也很正常,但就是在打 ...
- css水平垂直居中问题
水平居中: 行内元素:text-align:center; 块级元素:magin:0 auto; 子元素设置:position:absolute; left:50%; transform:tran ...
- jQuery进阶第三天(2019 10.12)
一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight =====> 获得元素content+padding的宽/高: offse ...
- vue filters过滤
<template> <div class="filters"> <h1 v-text="filtersTitle">< ...
- 2018-8-10-VisualStudio-修改配色
title author date CreateTime categories VisualStudio 修改配色 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...