D. BerDonalds
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

BerDonalds, a well-known fast food restaurant, is going to open a cafe in Bertown. The important thing is to choose the new restaurant's location so that it would be easy to get there. The Bertown road system is represented by n junctions, connected by m bidirectional roads. For each road we know its length. We also know that we can get from any junction to any other one, moving along the roads.

Your task is to find such location of the restaurant, that the shortest distance along the roads from the cafe to the farthest junction would be minimum. Note that the restaurant can be located not only on the junction, but at any point of any road.

Input

The first line contains two integers n and m () — the number of junctions and the number of roads, correspondingly. Then m lines follow, describing all Bertown roads. Each road is described by three integers ai, bi, wi(1 ≤ ai, bi ≤ n, ai ≠ bi; 1 ≤ wi ≤ 105), where ai and bi are the numbers of the junctions, connected by the i-th road, and wi is the length of the i-th road.

It is guaranteed that each road connects two distinct junctions, there is at most one road between any two junctions, and you can get from any junction to any other one.

Output

Print a single real number — the shortest distance from the optimal restaurant location to the farthest junction. The answer will be considered correct, if its absolute or relative error doesn't exceed 10 - 9.


比赛的时候想了一种做法;

先floyd,然后枚举每条边,在边上二分一个点使得这个点到其他点最大距离最小

但是一直WA,问题竟然是,这不是个单调函数是个单峰函数应该用三分!!!

然后貌似这个道卡三分了

二分是可以做的,直接二分答案ans,然后也是枚举每条边让其他点向这条边走ans距离,没有走到的地方覆盖,最后全覆盖了就是不可行

但是有复杂度更低的做法O(n^3)  参考http://www.cnblogs.com/lzqxh/archive/2013/03/05/2944834.html#2659117

枚举边后,对于每个点距离是min{d[u][i]+x,d[v][i]+L-x},是单峰函数,并且是一个折,所有点画出来长这样

最优解一定在最上面那条线的最低点取到

那就找所有交点

按照d[u][]大到小排序后,对于先后两个点a和b,他们的图像出现交点的条件就是d[v][a]<d[v][b]

还有一点,这个距离最多是个0.5  (这也解释了为什么本题精度那么奇怪)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,M=2e4+,INF=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} int n,m,u,v,w;
struct data{
int u,v,w;
}a[M];
int d[N][N];
void floyd(){
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
} int ans=INF;
int rnk[N][N],val[N];
bool cmp(int a,int b){return val[a]<val[b];}
void solve(){
floyd();
for(int i=;i<=n;i++){
for(int j=;j<=n;j++) rnk[i][j]=j,val[j]=d[i][j];
sort(rnk[i]+,rnk[i]++n,cmp);
//for(int j=1;j<=n;j++) printf("rnk %d %d %d\n",i,j,rnk[i][j]);
}
for(int i=;i<=n;i++) ans=min(ans,d[i][rnk[i][n]]<<);
for(int i=;i<=m;i++){
u=a[i].u,v=a[i].v,w=a[i].w;
for(int p=n,i=n-;i>=;i--){
if(d[v][rnk[u][i]]>d[v][rnk[u][p]]){//rnk[u][i] and rnk[u][p] has intersectioin
ans=min(ans,d[u][rnk[u][i]]+d[v][rnk[u][p]]+w);
p=i;
}
}
}
printf("%lf",ans/2.0);
} int main(){
n=read();m=read();
for(int i=;i<=n;i++) for(int j=i+;j<=n;j++) d[i][j]=d[j][i]=INF;
for(int i=;i<=m;i++){
a[i].u=read(),a[i].v=read(),a[i].w=read();
d[a[i].u][a[i].v]=d[a[i].v][a[i].u]=a[i].w;
}
solve();
}

CF266D. BerDonalds [图的绝对中心]的更多相关文章

  1. UML动态模型图简单介绍

    UML动态模型图描述了系统动态行为的各个方面,包括用例图.序列图.协作图.活动图和状态图.下面就每种图做一个简单介绍: 用例图 用例图描述系统外部的执行者与系统提供的用例之间的某种联系.所谓用例是指对 ...

  2. iOS10 UI教程视图的中心位置

    iOS10 UI教程视图的中心位置 center表示的是视图的中心位置属性,这个属性在相对的UI层次结构上工作,和frame类似.center属性是一个在父视图上定义视图的位置的简便方法.center ...

  3. 云计算和大数据时代网络技术揭秘(八)数据中心存储FCoE

    数据中心存储演化——FCoE   数据中心三大基础:主机 网络 存储 在云计算推动下,存储基础架构在发生演变 传统存储结构DAS.SAN在发展中遇到了布线复杂.能耗增多的缺点(原生性),需要对架构做根 ...

  4. [转载] Google数据中心网络技术漫谈

    原文: http://www.sdnlab.com/12700.html?from=timeline&isappinstalled=0#10006-weixin-1-52626-6b3bffd ...

  5. prefuse学习(二)显示一张图

    1.  把数据以点连线的方式在画面中显示 2.  数据按照数据的性别属性使用不同的颜色 3.  鼠标左键可以把图在画面中拖动 4.  鼠标右键可以把图放大或者缩小 5.  鼠标单击某个数据上,该数据点 ...

  6. H3C数据中心虚拟化解决方案技术白皮书

    缩略语清单: 缩略语 英文全名 中文解释 IDC Internet Data Center 互联网数据中心 VRF Virtual Router Forwarding 虚拟路由器转发 SMP Symm ...

  7. 图像Resize中0.5像素中心对齐的问题

    目录 0.5像素对齐的问题 0.5像素对齐的问题 1. 问题提出 在进行图像缩放时,偶尔会看到一些比较奇怪的代码,其中有一个就是0.5像素中心对齐的问题,例如在OpenCV线性插值的代码中有类似如下操 ...

  8. 【GNN】图神经网络小结

    图神经网络小结 图神经网络小结 图神经网络分类 GCN: 由谱方法到空域方法 GCN概述 GCN的输出机制 GCN的不同方法 基于谱方法的GCN 初始 切比雪夫K阶截断: ChebNet 一阶Cheb ...

  9. 思维导图VS金字塔原理

    作为常识,思维导图制作的核心元素是关键词,而金字塔原理制作的核心元素则是拓展的概要句子,这两种方式是当今人们常用的思维工具,本文对其做了对比,希望对你的选择有所帮助. 金字塔原理结构:从上到下三角形结 ...

随机推荐

  1. Django 用散列隐藏数据库中主键ID

    最近看到了一篇讲Django性能测试和优化的文章, 文中除了提到了很多有用的优化方法, 演示程序的数据库模型写法我觉得也很值得参考, 在这单独记录下. 原文的演示代码有些问题, 我改进了下, 这里可以 ...

  2. Spark环境搭建(下)——Spark安装

    1. 下载Spark 1.1 官网下载Spark http://spark.apache.org/downloads.html 打开上述链接,进入到下图,点击红框下载Spark-2.2.0-bin-h ...

  3. RxJava整合Retrofit遇到的问题总结

    一:初上手(填坑) Observable将事件序列执行完毕后,会回调Observe的onNext()方法和onCompleted()方法,当出现异常/错误时会调用onError()方法. 由此,我们推 ...

  4. Arrays类详解

    数组是数据结构中最简单的一种类型.在平常的使用上也比较多见.今天就来总结一下数组在使用过程中的一些心得 1.java中包装数组的一些基本用法的抽象类  java.util.Arrays.这个类中包含操 ...

  5. 用PHP,怎么获取PHP.ini中的文件上传最大的字节数。也就是默认的2M

    PHP中用ini_get函数来获取服务器允许的文件上传最大字节数,如:

  6. dedecms 图集标签{dede:productimagelist} {dede:field name='imgurls'}&nbs

    1.{dede:productimagelist}{/dede:productimagelist} 2.{dede:field name='imgurls'}{/dede:field} 这两个图集标签 ...

  7. phpStudy2016 配置多个域名期间遇到的问题

    http://www.cnblogs.com/ssfs/p/6255791.html 第一步 在C:\Windows\System32\drivers\etc下的hosts文件下添加   第二步   ...

  8. 关于IDE与环境变量的一点说明

    环境变量就是当计算机要执行操作时,在环境变量所制定的范围内查找该操作. 比如linux的ls命令,计算机就需要在$PATH规定的目录中寻找该ls的可执行文件. java的classpath,在该规定的 ...

  9. web.xml 报错

    1.The markup in the document following the root element must be well-formed. 原因是配置时没有 放在根下 <web-a ...

  10. Flexible Box布局基础知识详解

    1.基本概念,借用阮一峰老师的一张图: 容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis).主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫 ...