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. python之路----模块调用

    如何使用模块? 1 import 示例文件:自定义模块my_module.py,文件名my_module.py,模块名my_module #my_module.py print('from the m ...

  2. 负载均衡之-LVS

    负载均衡用的很多,这里对负载均衡做一个总结吧,总共包含下面几片博文. LVS负载均衡 keepalived负载均衡+高可用 haproxy负载均衡 nginx负载均衡 LVS负载均衡 LVS是章文嵩博 ...

  3. C_Learning (1)

    /数据类型及占用字节 char   1个字节{-128~127} int    2.4个字节,取决于平台是16位还是32位机子{-65536~65535} short int  2个字节{-32768 ...

  4. ms11_050漏洞攻击

    ms11_050漏洞攻击 开启msfconsole 查看针对MS11_050漏洞的攻击模块 进入模块 查看该模块的具体信息 设置paylaods 查看具体参数设置 设置其相关参数 攻击 ie浏览器发生 ...

  5. Android实践项目汇报(总结)

    天气客户端开发报告 1    系统需求分析 1.1功能性需求分析 天气预报客户端,最基本就是为用户提供准确的天气预报信息.天气查询结果有两种:一种是当天天气信息,信息结果比较详细,除温度.天气状况外还 ...

  6. 超频真的不难!G3258超频4.5GHz全攻略

    奔腾G3258搭配主板详解 [pconline 应用]目前DIY市场上最火热的装机组合莫过于奔腾20周年纪念版处理器G3258搭配B85芯片组主板,只要通过适当的超频,相对较低投入也能来不错的性能体验 ...

  7. C++ Compress Floder

    第三方函数.头文件.测试工程下载地址:http://download.csdn.net/detail/u012958937/8361733

  8. Python 中的几种矩阵乘法 np.dot, np.multiply, *【转】

    本文转载自:https://blog.csdn.net/u012609509/article/details/70230204 Python中的几种矩阵乘法1. 同线性代数中矩阵乘法的定义: np.d ...

  9. hash入门

    如果你已经确保自己的hash技巧已经入门,那么请左转这篇博文 首先介绍一下hash? 事实上是一种叫做蛤丝的病毒 以下讲到的hash都是OI中最常用到的hash方法:进制哈希 做法: 首先设一个进制数 ...

  10. [不屈的复习] - http://how2j.cn/

    http://how2j.cn/ 该教程网站分得比较规整!