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. Oracle提示错误消息ORA-28001: the password has expired

    首先,以SYS DBA身份进入sqlpuls 打开sqlpuls SQL->请输入用户名:sys as sysdba SQL->密码: 登录成功以后查询DBA用户状态 SQL->se ...

  2. [转载]ASP.NET中IsPostBack详解

    1.IsPostBack介绍Page.IsPostBack是一个标志:当前请求是否第一次打开. 调用方法为:Page.IsPostBack或者IsPostBack或者this.IsPostBack或者 ...

  3. Ubuntu下使用face_recognition进行人脸识别

    Face Recognition是一个基于Python的人脸识别库,在github上地址如下:https://github.com/ageitgey/face_recognition. 看着挺好玩,本 ...

  4. 20145317《网络对抗》Exp4 恶意代码分析

    20145317<网络对抗>Exp4 恶意代码分析 一.基础问题回答 (1)总结一下监控一个系统通常需要监控什么.用什么来监控. 通常监控以下几项信息: 注册表信息的增删添改 系统上各类程 ...

  5. 20145333茹翔 Exp5 MS08_067漏洞测试

    20145333茹翔 Exp5 MS08_067漏洞测试 实验过程 IP:kali:192.168.31.177.windows 2003 :192.168.31.223 使用命令msfconsole ...

  6. tf.multiply()和tf.matmul()区别

    (1)tf.multiply是点乘,即Returns x * y element-wise. (2)tf.matmul是矩阵乘法,即Multiplies matrix a by matrix b, p ...

  7. 简谈高通Trustzone的实现【转】

    本文转载自:https://blog.csdn.net/hovan/article/details/42520879 从trust zone之我见知道,支持trustzone的芯片会跑在两个世界. 普 ...

  8. Zookeeper一致性协议原理Zab

    ZooKeeper为高可用的一致性协调框架,自然的ZooKeeper也有着一致性算法的实现,ZooKeeper使用的是ZAB协议作为数据一致性的算法, ZAB(ZooKeeper Atomic Bro ...

  9. triggerHandler不执行事件默认值

    <input type="text" /> $('input').triggerHandler('focus');

  10. js中一些关于比较左右两边的值的题目

    alert(typeof(NaN)); alert(typeof(Infinity)); alert(typeof(null)); alert(typeof(undefined)); alert(Na ...