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

分析:最短路+二分。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#define ll long long
#define inf 1000000000
#define maxn 1005
using namespace std;
struct edge
{
int to,h,len;
edge(int x,int y,int z)
{
to=x;h=y;len=z;
}
};
vector<edge>e[maxn];
queue<int>q;
bool vis[maxn];
int d[maxn],n,m,s,t,H,maxh;
void spfa(const int s,int h)
{
while(!q.empty())q.pop();
for(int i=;i<=n;i++)
{
d[i]=inf;vis[i]=false;
}
d[s]=;vis[s]=true;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(e[u][i].h>=h&&d[e[u][i].to]>d[u]+e[u][i].len)
{
d[e[u][i].to]=d[u]+e[u][i].len;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
vis[u]=false;
}
}
int main()
{
int cas=;
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)break;
for(int i=;i<maxn;i++)e[i].clear();
int u,v,h,l;
for(int i=;i<m;i++)
{
scanf("%d%d%d%d",&u,&v,&h,&l);
if(h==-)h=inf;
e[u].push_back(edge(v,h,l));
e[v].push_back(edge(u,h,l));
}
scanf("%d%d%d",&s,&t,&H);
int lef=,r=H,maxh=,ans=inf;
while(lef<=r)
{
int mid=(r+lef)>>;
if(mid<=)break;
spfa(s,mid);
if(d[t]!=inf)
{
lef=mid+;
maxh=mid;
ans=d[t];
}
else r=mid-;
}
if(cas>) puts("");
printf("Case %d:\n",cas++);
if(ans==inf||maxh<)cout<<"cannot reach destination\n";
else {
printf("maximum height = %d\n",maxh);
printf("length of shortest route = %d\n",ans);
}
}
return ;
}

最新文章

  1. 去除项目中的SVN标记
  2. 绘图: Shape, Path
  3. duilib进阶教程 -- 扩展duilib的消息 (11)
  4. Android应用性能优化之使用SparseArray替代HashMap
  5. sharepint 数据视图 添加超链接
  6. magento如何获取某一产品的订单量代码
  7. 判断Windows操作系统的版本
  8. VS/Visual studio 源代码编辑器里的空处出现点号解决办法
  9. 常见的HTTP错误总结
  10. Eclipse查找类路径快捷方式
  11. SQL Server 127个SQL server热门资料汇总
  12. [C#]Array 添加扩展
  13. JS-运动框架
  14. 常用的 css 样式 记录
  15. Antlr v4入门教程和实例
  16. 学习day02
  17. [FWT] UOJ #310. 【UNR #2】黎明前的巧克力
  18. 《C#从现象到本质》读书笔记(八)第10章反射
  19. P10.3 usestock0.cpp
  20. [SSRS / RV] (.rdlc报表)冻结表头,固定行列标题

热门文章

  1. MongoDB 极简实践入门
  2. 使用Idea工具创建Maven WebApp项目
  3. day04 list tuple (补)
  4. List&lt;T&gt;.Distinct()
  5. Android 对话框(Dialogs)
  6. 20181113-3 Beta阶段贡献分配规则
  7. scrum立会报告+燃尽图(第二周第六次)
  8. 王者荣耀交流协会——第7次Scrum会议
  9. lintcode-401-排序矩阵中的从小到大第k个数
  10. 第三章 ServerSpcket用法详解