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次经过的最大的边最小是多少 ...
随机推荐
- PKU_campus_2018_H Safe Upper Bound
思路: 题目链接http://poj.openjudge.cn/practice/C18H/ 用2147483647除以最大素因子. 这里用了Pollard_rho因子分解算法,模板参考了http:/ ...
- 【学习笔记】HTML position(static、fixed、relative、absolute)
[本文转载] position的四个属性值:static.fixed.relative.absolute 下面分别讲述这四个属性:<div id="parent"> ...
- K-means算法Java实现
public class KMeansCluster { private int k;//簇的个数 private int num = 100000;//迭代次数 ...
- js图片轮播效果常见的产品无缝轮播
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- jmeter的JVM参数设置
JMeter用户可根据运行的计算机配置,来适当调整JMeter.bat中的JVM调优设置,如下所示: set HEAP=-Xms512m -Xmx512m set NEW=-XX:NewSize=12 ...
- COGS 2111. [NOIP2015普及]扫雷游戏
★ 输入文件:2015mine.in 输出文件:2015mine.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 扫雷游戏是一款十分经典的单机小游戏.在 n 行 ...
- 洛谷 P1216 [USACO1.5]数字三角形 Number Triangles(水题日常)
题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 ...
- Android(java)学习笔记182:多媒体之撕衣服的案例
1.撕衣服的案例逻辑: 是两者图片重叠在一起,上面我们看到的是美女穿衣服的图片,下面重叠(看不到的)是美女没有穿衣服的图片.当我们用手滑动画面,上面美女穿衣服的图片就会变成透明,这样的话下 ...
- 汇编4OPCODE
opcode原理 前缀域 切换操作数大小前缀 : 066h 可以将32位的操作数切换成16位的操作数 B8 00010000 | MOV EAX,0x100 66:B8 0001 | MOV ...
- 聊天室(C++客户端+Pyhton服务器)3.群功能添加
创建群 数据库 group_table(user, name) grpuser_table(grpname,user) 按下添加群按钮 // 创建群组void CUserDialog::OnBnCli ...