SECRET

时间限制:3000 ms  |  内存限制:65535 KB
难度:6
 
描述
Dr.Kong is constructing a new machine and wishes to keep it secret as long as possible. He has hidden in it deep within some forest and needs to be able to get to the machine without being detected. He must make a total of T (1 <= T <= 200) trips to the machine during its construction. He has a secret tunnel that he uses only for the return trips. The forest 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, Dr.Kong knows he cannot use any trail on the forest more than once and that he should try to use the shortest trails. Help Dr.Kong get from the entrance (landmark 1) to the secret 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 Dr.Kong can make all T trips without reusing a trail.
 
输入
There are multi test cases.Your program should be terminated by EOF.
Line 1: Three space-separated integers: N, P, and T
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.
输出
Line 1: A single integer that is the minimum possible length of the longest segment of 
Dr.Kong 's route.
样例输入
7 9 2
1 2 2
2 3 5
3 7 5
1 4 1
4 3 1
4 5 7
5 7 1
1 6 3
6 7 3
样例输出
5
来源
第四届河南省程序设计大赛
上传者
张云聪
    题目大意是给出一幅加权无向图,从起点走到终点走T次,每次都走最短路且每条路只能走一次,
问满足条件的方案中使得权值最小的那条边的权值达到最小,并输出。
  二分这个权值,然后将满足条件的边标记下。将所有能走的边的流量都置为1然后跑最大流,这样
最大流量就是能走的次数(从起点到终点)。
  

 #include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int N,P,T;
struct Edge{
int u,v,w;
}e[];
int g[][],vis[],d[];
bool bfs(){
memset(vis,,sizeof(vis));
vis[]=;
queue<int>q;
q.push();
d[]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=;i<=N;++i){
if(!vis[i]&&g[u][i]>){
vis[i]=;
d[i]=d[u]+;
q.push(i);
}
}
}
return vis[N];
}
int dfs(int u,int a){
if(u==N || a==) return a;
int flow=,f;
for(int i=;i<=N;++i){
if(g[u][i]&& d[i]==d[u]+ && (f=dfs(i,min(a,g[u][i])))>){
g[u][i]-=f;
g[i][u]+=f;
flow+=f;
a-=f;
if(!a) break;
}
}
return flow;
}
int solve(){
int res=;
while(bfs()){
res+=dfs(,inf);
}
return res;
}
bool ok(int mid){
memset(g,,sizeof(g));
for(int i=;i<=P;++i){
if(e[i].w<=mid){
g[e[i].u][e[i].v]++;
g[e[i].v][e[i].u]++;
}
}
return solve()>=T;
}
int main(){
while(scanf("%d%d%d",&N,&P,&T)!=EOF){
for(int i=;i<=P;++i) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
int l=,r=;
while(l<r){
int mid=l+((r-l)>>);
if(ok(mid)) r=mid;
else l=mid+;
}
cout<<l<<endl;
}
return ;
}

最新文章

  1. SQL语句
  2. hibernate用setResultTransformer转换
  3. MapReduce基础知识
  4. C# 5.0 新特性——Async和Await使异步编程更简单
  5. axis2_1.6.2之构建web端和客户端 .
  6. Git基本交互流程图
  7. AspNetPager 自定义html
  8. JVM专题
  9. SQL优化(2)
  10. Grading
  11. (转)JAVA路径问题及命令行编译运行基础(linux下)
  12. javascript 验证身份证
  13. 谨记给UpdatePanel中动态添加的控件赋ID
  14. JAVA线程间的状态转换
  15. MySql 动态语句
  16. Capslock+ 键盘党都爱的高效利器 - 让 Windows 快捷键操作更加灵活强大
  17. 解析搜狗实验室精简版数据:1、批量将.txt编码格式转化为utf8 2、解析提取数据
  18. Selenium 、WebDriver :Capability
  19. 响应式布局与bootstrap框架
  20. 41 Pain and Pain Management 疼痛与疼痛管理

热门文章

  1. OAuth : open Authorization 开发授权
  2. 教你如何在linux下查看服务是否已经启动或者关闭
  3. (mac)阿里云ECS服务器配置过程
  4. android 简单的控件前端代码
  5. 使用openssl生成SSL证书完全参考手册
  6. http://bugs.mysql.com/bug.php?id=72123
  7. html 5实用特性之data属性
  8. troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm
  9. 对于“机器视觉(computer version)”的反思
  10. BZOJ 3339 &amp;&amp; luogu4137 Rmq Problem / mex(莫队)