BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
n<=200个点m<=40000条边无向图,求 t次走不经过同条边的路径从1到n的经过的边的最大值 的最小值。
最大值最小--二分,t次不重边路径--边权1的最大流。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
using namespace std; int n,m,t;
#define maxn 211
#define maxm 160011
struct Edge{int to,next,v;}edge[maxm];int first[maxn],le=;
void in(int x,int y,int v) {Edge &e=edge[le];e.to=y;e.v=v;e.next=first[x];first[x]=le++;}
void insert(int x,int y,int v) {in(x,y,v);in(y,x,v);}
const int inf=0x3f3f3f3f;
struct network
{
struct Edge{int to,next,cap,flow;}edge[maxm];int first[maxn],le,n,s,t;
void clear(int n)
{
memset(first,,sizeof(first));
le=;this->n=n;
}
void in(int x,int y,int cap) {Edge &e=edge[le];e.to=y;e.cap=cap;e.flow=;e.next=first[x];first[x]=le++;}
void insert(int x,int y,int cap) {in(x,y,cap);in(y,x,);}
int que[maxn],head,tail,dis[maxn],cur[maxn];
bool bfs()
{
memset(dis,,sizeof(dis));
dis[s]=;
que[head=(tail=)-]=s;
while (head!=tail)
{
const int now=que[head++];
for (int i=first[now];i;i=edge[i].next)
{
const Edge &e=edge[i];
if (e.cap>e.flow && !dis[e.to])
{
dis[e.to]=dis[now]+;
que[tail++]=e.to;
}
}
}
return dis[t];
}
int dfs(int x,int a)
{
if (x==t || !a) return a;
int flow=,f;
for (int &i=cur[x];i;i=edge[i].next)
{
Edge &e=edge[i];
if (dis[e.to]==dis[x]+ && (f=dfs(e.to,min(a,e.cap-e.flow)))>)
{
flow+=f;
e.flow+=f;
edge[i^].flow-=f;
a-=f;
if (!a) break;
}
}
return flow;
}
int dinic(int s,int t)
{
this->s=s;this->t=t;
int ans=;
while (bfs())
{
for (int i=;i<=n;i++) cur[i]=first[i];
ans+=dfs(s,inf);
}
return ans;
}
}g;
bool check(int x)
{
g.clear(n);
for (int i=;i<=n;i++)
for (int j=first[i];j;j=edge[j].next)
{
const Edge &e=edge[j];
if (e.v<=x) g.insert(i,e.to,);
}
return g.dinic(,n)>=t;
}
int x,y,v;
int main()
{
scanf("%d%d%d",&n,&m,&t);
int Max=;
memset(first,,sizeof(first));
for (int i=;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&v);
insert(x,y,v);
Max=max(Max,v);
}
int L=,R=Max+;
while (L<R)
{
int mid=(L+R)>>;
if (check(mid)) R=mid;
else L=mid+;
}
printf("%d\n",L);
return ;
}
BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机的更多相关文章
- [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 神秘的挤奶机 网络流 + 二分答案
Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...
- [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】
题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...
- 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 ...
- 【poj2455】 Secret Milking Machine
http://poj.org/problem?id=2455 (题目链接) 题意 给出一张n个点,p条边的无向图,需要从1号节点走到n号节点一共T次,每条边只能经过1次,问T次经过的最大的边最小是多少 ...
随机推荐
- position 位置、表单
一.position 位置 1.只要使用了定位,必须有一个相对的参照物 2.具体定位的那个元素需加position:absolute:(绝对的) 绝对的:就是具体到某一个地方,特别详细的意思 ...
- vs 2017 下 千万不要装force utf8 这个插件
千万不要装!!! 装了之后,传文件到linux系统下,各种xml和makefile报错(如下) Makefile:1: *** 遗漏分隔符 . 停止
- 新建cordova应用
使用命令行(本例命令行均使用as或webstrom的命令行),在任意目录输入以下命令新建cordova应用 cordova create capp1 com.cesc.ewater.capp1 其中c ...
- iOS 解决iOS 9下的http请求发送失败问题
iOS9中 因为系统要求所有的请求都必须使用https, 所以发送http请求会失败,如果想让程序能够兼容http请求 在info.plist中添加以下代码: 这里需要做的是右键info.plist文 ...
- 分类IP地址(A、B、C类)的指派范围、一般不使用的特殊IP地址
分类IP地址(A.B.C类)的指派范围.一般不使用的特殊IP地址 A类地址:0开头,8位网络号 B类地址:10开头,16位网络号 C类地址:110开头,24位网络号 D类地址:1110开头,多播地址 ...
- Zotero文献管理神器使用
为什么使用Zotero管理论文? 1.可以从网上剪藏 2.可以查询 3.有作者 标题 期刊 索引 4.word自动生成论文索引 把pdf文件导入Zotero 按住ctrl+shift拖动pdf文件,就 ...
- 面向对象的设计的SOLID原则
S.O.L.I.D是面向对象设计和编程中5个重要编码规则的首字母的缩写. - SRP The Single Responsibility Principle 单一责任原则 当需要修改某个类的时候原因有 ...
- java_日期和时间
1.System类中的currentTimeMillis:1970年1.1到现在的毫秒数 public class DateTest { public static void main(String[ ...
- 最短路 || HDU 2066 一个人的旅行
本草的旅行故事(✺ω✺),可以从S个点中的任意一个开始,到达D个点中的任意一个,求最短路 *解法:把草儿的家记成点0,S个点与0的距离为0,然后spfa求最短路 又是改了一万次,①多组数据啊 ②改完多 ...
- idea创建Maven项目时Maven插件内看不到mybatis-generator
创建Maven项目时插件配置添加了mybatis-generator但是右侧maven project始终没有看到插件 需要放在和pluginManagement同级别,修改配置如下: