nyoj-310-河南省第四届省赛题目-二分+dinic
- 描述
- 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的更多相关文章
- poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分, dinic, isap
poj 2391 Ombrophobic Bovines, 最大流, 拆点, 二分 dinic /* * Author: yew1eb * Created Time: 2014年10月31日 星期五 ...
- POJ2391 Floyd+离散化+二分+DINIC
题意: 有n个猪圈,每个猪圈里面都有一定数量的猪(可能大于当前猪圈的数量),每个猪圈都有自己的容量,猪圈与猪圈之间给出了距离,然后突然下雨了,问多久之后所有的猪都能进圈. 思路: ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...
- [河南省ACM省赛-第四届] 表达式求值(nyoj 305)
栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...
- 河南省第四届ACM省赛(T3) 表达式求值
表达式求值 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...
- [河南省ACM省赛-第三届] 房间安排 (nyoj 168)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...
- [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...
- [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...
- [河南省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 ...
随机推荐
- 有趣的js匿名函数写法(function嵌套)
例子没有什么实际意义,只能做为思路参考 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&quo ...
- Linux中Postfix邮件接收配置(四)
Dovecot介绍 MRA邮件取回代理也有很多如courier-imap,cyrus-imap和dovecot这三个个工具,下面重点介绍Dovecot: 1.高安全性.据 Dovecot 的作者声称, ...
- phonegap 开发案例
PhoneGap-Android-HTML5-WebSocket 不使用任何框架,教你制作网页滑动切换效果 http://www.csdn.net/article/2012-04-17/2804644 ...
- PHP中private和public还有protected的区别
原文链接:http://www.thinkphp.cn/code/1898.html <? //父类 class father{ public function a(){ echo " ...
- windows服务与自启动程序的区别(转载)
转载:http://blog.csdn.net/anddy926/article/details/8464142 在客户端服务器项目实践中,作为服务端必须保持程序的24小时不间断运行,需要做一个监控, ...
- DD-WRT自定义脚本更新花生壳DDNS
N年以前买了一个tp-link 841n v7,一直用的还算可以吧,除了不定期重启路由器,不然网速慢的龟爬啊!这也是TP原厂固件的通病,于是刷了DD-WRT,话说DD确实很爽,除了功能强大之外,而且很 ...
- PyCharm/IDEA 使用技巧总结
基本概念 IDEA 没有类似 Eclipse 的工作空间的概念(workspace),最大单元就是 Project.这里可以把 Project 理解为 Eclipse 中的 workspace.Mod ...
- Several Service Control Manager Issues (Event ID's 7000, 7009, 7011)
https://answers.microsoft.com/en-us/windows/forum/windows_7-performance/several-service-control-mana ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer 最大生成树 lca
大概就是要每两个点 只能有一条路径,并且约束,最短的边用来砌墙,那么反之的意思就是最大的边用来穿过 故最大生成树 生成以后 再用lca计算树上两点间的距离 (当然防止生成树是一条链,可以用树的重心作为 ...
- 51NOD 1099 任务执行顺序
来源:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 前天没睡好 昨天做题闷闷沉沉的 好多一眼题 都瞎做了 这题今 ...