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. oracle数据泵备份与恢复库

    假如  导出库的用户名是tiger,密码是1  导入到用户名是scott,密码是1 备份库 expdp tiger/1@orcl dumpfile=expdp.dmp DIRECTORY=dpdata ...

  2. Docker+Jenkins持续集成环境(4):使用etcd+confd实现容器服务注册与发现

    前面我们已经通过jenkins+docker搭建了基本的持续集成环境,实现了服务的自动构建和部署,但是,我们遇到一个问题,jenkins构建出来的镜像部署后,需要通过ip:port去访问,有什么更好的 ...

  3. 关于Swing窗体有时候要放大缩小边框才能显示问题?

    有时候会出现编写swing窗体后添加的组件在run之后显示不出来的问题.如图: 搜了下解决办法.此时如果是程序里面有panel组件的话,应该这样: labels[i] = new Label(lett ...

  4. 网站地图怎么做?dedecms网站地图制作方法听语音

    网站地图怎么生成?下面分享织梦dedecms系统网站地图的生成方式,怎么制作网站地图,方法很简单.下面介绍一下网站地图优化方法及制作方法. 工具/原料 一个网站 方法/步骤 第一步 登录网站后台 第二 ...

  5. android 基础03 -- Intent

    Android 中的 Intent 是将要执行的操作的一种抽象的描述,是一个用于Android 各个组件之间传递消息的对象. Intent 的基本用法 Intent 基本的使用方法主要有三种: 启动一 ...

  6. 辩证看待 iostat

    前言 经常做系统分析会接触到很多有用的工具,比如 iostat,它是用来分析磁盘性能.系统 I/O 的利器. 本文将重点介绍 iostat 命令的使用,并分析容易引起误解的几个指标. iostat i ...

  7. tomcat三种启动不同的启动方式

    Linux下tomcat服务的启动.关闭与错误跟踪,通常通过以下几种方式启动关闭tomcat服务: 切换到tomcat主目录下的bin目录 1. 启动tomcat服务 方式一:直接启动 ./start ...

  8. 一个使用物理引擎的WebGL3D场景

    这是一个类似第三人称射击游戏(TPS)的3D场景,可以通过https://ljzc002.github.io/FPS2/index.html访问.场景运行效果如下图: 场景环境由一个天空盒和一个地面网 ...

  9. Windows脚本修改主机名-不重启

    windows通过脚本方式修改主机名的方法有很多种,下面介绍修改注册表方式的脚本. 使用方法: 1 打开cmd,假如脚本名为ModifyHostname.bat 2 执行脚本,并加入脚本参数,其中第一 ...

  10. tp5无法隐藏index.php入口文件

    一: 官方文件: <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on Rewrite ...