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次经过的最大的边最小是多少 ...
随机推荐
- UML建模图实战笔记
一.前言 UML:Unified Modeling Language(统一建模语言),使用UML进行建模的作用有哪些: 可以更好的理解问题 可以及早的发现错误或者被遗漏的点 可以更加方便的进行组员之间 ...
- lavarel功能总结
详细可参见笔记:laraval学习笔记(二) 路由 route 绑定模型,绑定参数 模版 blade .blade.php后缀,有laravel自己的模版语法 模型 model 如果用create创建 ...
- 从源码中无法看出函数所在的js脚本的解决方法
通过设置断点调试使js脚本自动出现
- Unity查找物体的四大主流方法及区别
GameObject.Find()优点: 使用简单方便不会因为重名而报错,同时查找的是自上而下的第一个物体缺点 不能查找被隐藏的物体,否则出现“空引用异常”,这是很多新人在查找出现空引用bug的原因. ...
- JS:输出9*9乘法表
<html> <head> <title>9*9 multiplication table</title> </head> <body ...
- python小随笔
关于pip安装 .\pip.exe install --ignore-installed --upgrade tensorflow-gpu python可视化库 Seaborn:是一个基于matplo ...
- QT +菜单栏和工具栏
#include "mainwindow.h" #include <QMenuBar>//菜单栏需要的头文件 #include <QMenu>//菜单 #i ...
- gcc编译问题
gcc avl.o hash.o list.o rb.o example.o -o 123.exe 多个.o输出 exe -c和-o都是gcc编译器的可选参数.-c表示只编译(compile)源文件但 ...
- Oracle中的DDL,DML,DCL总结
转自http://blog.csdn.net/w183705952/article/details/7354974 DML(Data Manipulation Language,数据操作语言):用于检 ...
- luogu 数列找不同-莫队
https://www.luogu.org/problemnew/show/P3901 了解过莫队的人应该都清楚,莫队是一个优化的暴力,可以在相对暴力比较优的时间中,求出一段序列内的某些性质(例:数字 ...