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 ...
随机推荐
- 机器学习、深度学习以及人工智能正在快速演进(ML、DL、AI)
机器学习.深度学习以及人工智能正在快速演进 机器学习.深度学习和人工智能(ML.DL和AI)是彼此相关的概念,他们正在改变不知多少行业,改变其自身管理模式,同时改变做出决策的方式.显然,ML.DL和A ...
- 在IBM学到的东西,到底对我的程序生涯产生了多大的影响
我和很多人交流过一个有趣的现象,那就是刚毕业到30岁这段时间,会觉得时间过得很慢,总觉得自己还很年轻,但是一旦过了30岁,时间就如白驹过隙,一年又一年飞逝而过. 我自己也是,眼瞅着毕业快15年了,15 ...
- 来了解一下Redis的分布式锁
分布式锁本质上要实现的目标就是在 Redis 里面占一个“茅坑”,当别的进程也要来占 时,发现已经有人蹲在那里了,就只好放弃或者稍后再试. 占坑一般是使用 setnx(set if not exist ...
- Centos 更改系统时间
.date //查看本地 .hwclock --show //查看硬件的时间 .如果硬件的时间是对不上,那就对硬件的时间进行修改 .hwclock --set --date '2222-22-22 2 ...
- python的re正则表达式模块
元字符 . * + ? ^ $ { } [ ] - \ . 匹配除了/n之外的任意一个字符 * 匹配*前面的单个字符任意次,即[0,+∞] + 匹配 ...
- P2864 [USACO06JAN]树林The Grove
P2864 [USACO06JAN]树林The Grove 神奇的射线法+bfs 裸的bfs很难写....... 那么我们找一个最外围障碍点,向图的外边引一条虚拟射线. 蓝后bfs时经过这条射线奇数次 ...
- Effective TensorFlow Chapter 4: TensorFlow中的广播Broadcast机制【转】
本文转载自:https://blog.csdn.net/LoseInVain/article/details/78763303 TensorFlow支持广播机制(Broadcast),可以广播元素间操 ...
- Chromosome coordinate systems: 0-based, 1-based
From: https://arnaudceol.wordpress.com/2014/09/18/chromosome-coordinate-systems-0-based-1-based/ I’v ...
- C# 代码设置DataGrid列属性
1 DataGridTableStyle dts = new DataGridTableStyle(); 2 dataGrid1.TableStyles.Clear(); 3 dts.MappingN ...
- js delete可以删除对象属性及变量
,对象属性删除 function fun(){ this.name = 'mm'; } var obj = new fun(); console.log(obj.name);//mm delete o ...