原题链接: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. hive的内置函数和自定义函数

    一.内置函数 1.一般常用函数 .取整函数 round() 当传入第二个参数则为精度 bround() 银行家舍入法:为5时,前一位为偶则舍,奇则进. .向下取整 floor() .向上取整 ceil ...

  2. 完美的【去重留一】SQL

    DELETE consum_record FROM consum_record, ( SELECT min(id) id, user_id, monetary, consume_time FROM c ...

  3. Python 装饰器Decorator(二)

    对于上一篇“”Python闭包“”随笔中提到的make_averager()函数的如下实现,我们把历史值保存在列表里,每次计算平均值都需要重新求和,当历史值较多时,需要占用比较多的空间并且效率也不高. ...

  4. plsql 永久注册码

    注册码:Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserial Number:601769 password:xs374ca 可用

  5. PAT L1-034 点赞

    https://pintia.cn/problem-sets/994805046380707840/problems/994805098188750848 微博上有个“点赞”功能,你可以为你喜欢的博文 ...

  6. 高性能的HTTP代理 LittleProxy

    引用: https://github.com/adamfisk/LittleProxy 拦截和操纵HTTPS流量,LittleProxy使用中间人(MITM)管理器. LittleProxy的默认实现 ...

  7. Java web 强制301跳转

    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location" ...

  8. 【C++】C++的构造函数

    构造函数是特殊的成员函数,只要创建类类型的对象,都要执行构造函数.构造函数的工作是保证每个对象的数据成员具有合适的初始值. class Sales_Item { public: //operation ...

  9. 【前端学习笔记】JavaScript JSON对象相关操作

    //JSON方法 //JSON.parse(); var json = '{"name":"zj","age":23}'; JSON.par ...

  10. Vue 取出记录数后,页面显示刚开始显示部分,点击更多显示全部

    实例的实现,是使用computed计算属性,还有对数组使用.slice函数,不改变原数据对象. <div id="app"> <ul> <li v-f ...