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 ;
}

nyoj-310-河南省第四届省赛题目-二分+dinic的更多相关文章

  1. poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap

    poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...

  2. POJ2391 Floyd+离散化+二分+DINIC

    题意:       有n个猪圈,每个猪圈里面都有一定数量的猪(可能大于当前猪圈的数量),每个猪圈都有自己的容量,猪圈与猪圈之间给出了距离,然后突然下雨了,问多久之后所有的猪都能进圈. 思路:     ...

  3. [河南省ACM省赛-第四届] 序号互换 (nyoj 303)

    相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...

  4. [河南省ACM省赛-第四届] 表达式求值(nyoj 305)

    栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  5. 河南省第四届ACM省赛(T3) 表达式求值

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...

  6. [河南省ACM省赛-第三届] 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...

  7. [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...

  8. [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...

  9. [河南省ACM省赛-第三届] 聪明的kk (nyoj 171)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171 动态规划: d(i,j) = max{d(i-1, j), d(i, j-1)}+m ...

随机推荐

  1. 神州行省内流量套餐6元500M申请,发送BLSN6到10086即可

    神州行流量套餐,神州行省内流量套餐6元500M申请,发送BLSN6到10086即可申请开通专属流量包,比全国5元30M划算多了4G全国流量套餐 5元/30M 10元/100M 20元/300M 30元 ...

  2. pyDay7

    内容来自廖雪峰的官方网站 1.如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). 2.只要是可迭代对象,无论有无下标, ...

  3. shell中参数及带色彩打印

    shell脚本中的一些函数参数说明如下: #!/bin/bash echo 显示参数的个数: $# echo 以单个字符串把每个参数连接起来: $* echo 显示脚本当前运行的进程id: $$ ec ...

  4. 查询oracle数据库里面所有的表名

    如果是当前用户,"select * from tab"即可

  5. vc编辑器常用设置

    代码格式化 1.选中代码: 2.ctrl+K: 3.ctrl+F; 显示行号

  6. 动态规划(Dynamic Programming)

    introduction 大部分书籍介绍"动态规划"时,都会从"菲波纳切数列"讲起. 菲波纳切数列 递归解法 C++ 代码如下 unsigned long in ...

  7. PHP微信公众号后台开发(Yii2实现)

    本文内容较多,包括微信接入.获取微信用户信息.微信支付.JSSDK配置参数获取等部分.如果读者对微信开发没有一个主观上的认识,那么建议读者先研读微信公众平台开发者文档,然后再阅读本文,效果更佳!另外本 ...

  8. Linux 进程学习笔记

    1.什么是程序?什么是进程?它们有什么区别? 定义: 程序:程序(Program)是一个静态的命令集合,程序一般放在磁盘中,然后通过用户的执行来触发.触发后程序会加载到内存中成为一个个体,就是进程. ...

  9. 20145104张家明 《Java程序设计》第7周学习总结

    20145104张家明 <Java程序设计>第7周学习总结 教材学习内容总结 第13章 简单认识时间和日期 -时间的度量:GMT.UT.TAI.UTC.Unix.epoch. -UTC:保 ...

  10. 20145106java实验四

    实验名称:Java网络编程 实验内容: 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 结对小伙伴 20145109竺文君 博客地址: 在本次实验中,是以我作为服务 ...