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次经过的最大的边最小是多少 ...
随机推荐
- AJPFX关于Swing组件的总结
默认布局管理器是流式布局(FlowLayout) 按钮的建立: jb1=new JButton("香蕉") 面板的建立:jp1=new JPanel(); 设置JFrame的标题: ...
- Android CursorAdapter的使用
CursorAdapter继承于BaseAdapter,为Cursor和ListView连接提供了桥梁. 首先看一下CursorAdapter的部分源码: /** * @see android.wid ...
- Python behave in BDD
BDD概念 全称 Behavior-driven development 中文 行为驱动开发 概念 是敏捷软件开发技术的一种,鼓励各方人员在一个软件项目里交流合作,包括开发人员.测试人员和非技术人员或 ...
- Netbeans调试教程
官方教程:Netbeans调试 CC++ 项目教程.docx 1.步过: 就是把函数当成一条指令来调用 比如上面就是光执行fun(i),不会到函数里面去 2.步入 就是进入函数里面执行 3.步出 就是 ...
- 2019年今日头条机试_JAVA后台岗_第二题
使用map的递推,java对象做key需要重写equeal,hashCode方法,使拥有相同属性值的对象被识别为同一对象. import java.util.*; class Cat{ public ...
- Uniform Resource Identifier
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier "URI" redirects here. For othe ...
- mybatis+oracle 完成插入数据库,并将主键返回的注意事项
mybatis+oracle 完成插入数据库,并将主键返回的注意事项一条插入语句就踩了不少的坑,首先我的建表语句是: create table t_openapi_batch_info( BATCH_ ...
- free - 显示系统中已用和未用的内存空间总和.
总览 (SYNOPSIS) free [-b | -k | -m] [-o] [-s delay ] [-t] [-V] 描述 (DESCRIPTION) free 显示 系统中 已用和未用的 物理内 ...
- uva12099 The Bookcase
这道题超经典.dp和优化都值得看一看.因为i+1只和i有关,用滚动数组节省空间暑假第一次做感觉很困难,现在看就清晰了很多 #include<cstdio> #include<cstr ...
- JavaEE-09 Ajax与jQuery在JavaEE项目中的使用
学习要点 JavaScript实现Ajax jQuery实现Ajax JSON JSON-LIB FastJSON JavaScript实现Ajax 认识Ajax 旧版百度地图 百度搜索自动补全 百度 ...