2455 Secret Milking Machine //二分答案+SAP
来源:互联网 发布:证券公司软件哪家好 编辑:程序博客网 时间:2024/06/06 08:58
Description
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
* 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
Sample Input
7 9 21 2 22 3 53 7 51 4 14 3 14 5 75 7 11 6 36 7 3
Sample Output
5
Hint
Huge input data,scanf is recommended.
Source
这道题的陷阱还是不少的
首先是二分答案,注意二分答案的格式,最后输出的答案是L,而不是MID,注意!!!
再者,注意重边啊!!!!因为题目大意是说只能走一次一条边,却没有说只能一次走一个点,所以的话,就是把存在的边二分答案的时候都放进数组中,进行SAP,即可得到答案。
WA了很多次,我还是太弱了。
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
const int V=210,E=400100;
struct NODE
{
int u,v,w;
NODE(int uu,int vv,int ww):u(uu),v(vv),w(ww) {}
};
vector<NODE> q;
struct edge
{
int aim,cap;
edge *next,*pair;
edge() {}
edge(int t,int c,edge *n):aim(t),cap(c),next(n) {}
void* operator new(unsigned,void* p)
{
return p;
}
}*e[V],Te[E+E],*Pe=Te;
int num[V],dis[V];
int n,p,tt,s,t;
int augment(int u,int augc)
{
if(u==t)return augc;
int d,tmp=n-1;
for(edge *i=e[u]; i; i=i->next)if(i->cap)
{
if(dis[u]==dis[i->aim]+1)
{
d=augment(i->aim,augc<i->cap?augc:i->cap);
i->cap-=d,i->pair->cap+=d;
if(d||dis[s]==n)return d;
}
if(dis[i->aim]<tmp)tmp=dis[i->aim];
}
if(!--num[dis[u]])dis[s]=n;
num[dis[u]=tmp+1]++;
return 0;
}
void init(int f)
{
int u,v,w;
memset(e,0,sizeof(e));
for(int i=0;i<q.size();i++)
{
NODE x=q[i];
u=x.u, v=x.v, w=x.w;
if(w<=f)
{
e[u]=new(Pe++)edge(v,1,e[u]);
e[v]=new(Pe++)edge(u,1,e[v]);
e[u]->pair=e[v];
e[v]->pair=e[u];
}
}
}
bool isap()
{
memset(dis,0,sizeof(dis));
memset(num,0,sizeof(num)),num[0]=n;
int flow=0;
s=1,t=n;
while(dis[s]<n) flow+=augment(s,0xfffffff);
if(flow>=tt) return true;
return false;
}
int main()
{
while(scanf("%d%d%d",&n,&p,&tt)!=EOF)
{
q.clear();
int front=10000000,top=-10000000;
for(int i=1;i<=p;i++)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
q.push_back(NODE(x,y,c));
if(c>top) top=c;
if(c<front) front=c;
}
while(front<=top)
{
int mid=(front+top)/2;
init(mid);
if(isap()) top=mid-1;
else front=mid+1;
}
printf("%d/n",front);
}
return 0;
}
- 2455 Secret Milking Machine //二分答案+SAP
- POJ 2455 Secret Milking Machine(二分答案+最大流)
- POJ 2455 Secret Milking Machine 最大流 二分答案
- POJ 2455 Secret Milking Machine (二分答案+最大流)
- POJ2455 Secret Milking Machine ——二分答案+网络流
- POJ2455 Secret Milking Machine 典型二分答案+最大流判定
- poj2455 Secret Milking Machine(二分答案+最大流)
- 【最大流+dinic+二分】北大 poj 2455 Secret Milking Machine
- poj 2455 Secret Milking Machine 最大流+二分查找
- poj - 2455 - Secret Milking Machine(最大流+二分)
- POJ 2455 Secret Milking Machine(二分+最大流)
- poj 2455 Secret Milking Machine 二分+最大流
- POJ 2455 — Secret Milking Machine 网络流+二分
- POJ 2455--Secret Milking Machine【二分枚举 && 最大流 && 经典】
- POJ 2455 Secret Milking Machine(二分+最大流)
- POJ 2455 Secret Milking Machine && 二分枚举 + 最大流
- poj 2455 Secret Milking Machine(二分枚举+最大流)
- Poj 2455 Secret Milking Machine【二分+最大流】
- 铸造JavaWeb利器
- sharepoint 自定义服务器代码的页面(二)
- 程序员面试题精选--(06)第一个只出现一次的字符
- tiles框架的使用
- .NET 事件模型教程(一)
- 2455 Secret Milking Machine //二分答案+SAP
- iphone 中对象之间通讯
- SELECT TOP N 问题
- 跪求 OMA DM协议和系统架构类文档
- TC插件
- C语言函数—数学函数
- current->pid && current->tgid
- list,set,map,数组间的相互转换
- sql 语句去多行重复值查询