原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2363

分析:最短路+二分。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#define ll long long
#define maxn 105
#define inf 0x7fffffff
using namespace std;
int T,n,m,low,up;
int h[maxn],map[maxn][maxn],h1[maxn];
int d[maxn];
bool vis[maxn];
struct edge
{
int to,len;
edge(int x,int y)
{
to=x;len=y;
}
};
vector<edge>e[maxn];
queue<int>q;
void spfa(const int s)
{
while(!q.empty())q.pop();
for(int i=;i<=n;i++)
{
d[i]=inf;vis[i]=false;
}
d[s]=;vis[s]=true;
if(h[s]<low||h[s]>up)return;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(h[e[u][i].to]>=low&&h[e[u][i].to]<=up)
{
int tmp=d[u]+e[u][i].len;
if(d[e[u][i].to]>tmp)
{
d[e[u][i].to]=tmp;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
}
vis[u]=false;
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
for(int i=;i<maxn;i++)e[i].clear();
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&h[i]);
h1[i]=h[i];
}
sort(h1+,h1+n+);
int u,v,len;
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&len);
e[u].push_back(edge(v,len));
e[v].push_back(edge(u,len));
}
int dif=inf,ans,minlen=inf;
int l=,r=h1[n]-h1[];
while(l<=r)
{
int mid=(l+r)>>;
bool flag=false;
for(int i=;i<=n;i++)
{
low=h1[i];
up=low+mid;
spfa();
if(d[n]!=inf)
{
flag=true;
ans=d[n];
break;
}
}
if(flag)
{
r=mid-;
if(dif>mid)
{
dif=mid;
minlen=ans;
}
else if(dif==mid&&ans<minlen)
minlen=ans;
}
else l=mid+;
}
printf("%d %d\n",dif,minlen);
}
return ;
}

HDU--2363的更多相关文章

  1. hdu 2363(枚举+最短路好题)

    Cycling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  5. hdu 3191 How Many Paths Are There (次短路径数)

    How Many Paths Are There Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  6. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  7. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  10. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Python基础入门(模块和包)

    1 模块 1.1 什么是模块 在 Python 中,一个 .py 文件就称之为一个模块(Module). 我们学习过函数,知道函数是实现一项或多项功能的一段程序 .其实模块就是函数功能的扩展.为什么这 ...

  2. 【坚持】Selenium+Python学习之从读懂代码开始 DAY3

    2018/05/15 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) #No.1 list = [1, 2, 3, 4] ...

  3. 基于marathon-lb的服务自发现与负载均衡

    参考文档: Marathon-lb介绍:https://docs.mesosphere.com/1.9/networking/marathon-lb/ 参考:http://www.cnblogs.co ...

  4. cinder创建volume的流程-简单梳理

    1. cinder-api接收到创建的请求,入口:cinder.api.v2.volumes.VolumeController#create,该方法主要负责一些参数的重新封装和校验,然后调用cinde ...

  5. 武汉天喻信息 移动安全领域 SE(Secure Element)

    产品简介: SE(Secure Element)为安全模块,是一台微型计算机,通过安全芯片和芯片操作系统(COS)实现数据安全存储.加解密运算等功能.SE可封装成各种形式,常见的有智能卡和嵌入式安全模 ...

  6. 搜索引擎Elasticsearch REST API学习

    Elasticsearch为开发者提供了一套基于Http协议的Restful接口,只需要构造rest请求并解析请求返回的json即可实现访问Elasticsearch服务器.Elasticsearch ...

  7. Solr初步研究

    Solr是一个高性能,采用Java5开发,Solr基于Lucene的全文搜索服务器.同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展并对查询性能进行了优化,并且提供 ...

  8. laraven安装记录

    版本4.2.11 下载地址:https://codeload.github.com/laravel/laravel/zip/v4.2.11 步骤: 1.解压到目录 2.下载composer,并放到/u ...

  9. Django内置的分页模块

    自定义分页 未封装版: 优点:直观 缺点:代码乱,不易维护,可拓展性差 data = [] for i in range(1, 302): tmp = {"id": i, &quo ...

  10. html5兼容

    You can download the latest version of HTML5shiv from github or reference the CDN version at https:/ ...