加了一些花的最短路,点的个数为500不需要堆优化,改一下dij的判断条件就可以了。

上代码:

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f; struct node
{
int id;
int cost;
int time;
}; int s,e;
int n,m;
vector<int> line0;
vector<int> line1;
vector<node> edge[maxn];
int d0[maxn];
int d1[maxn]; void build_map()
{
int v1,v2,ow,cost,time;
scanf("%d %d %d %d %d",&v1,&v2,&ow,&cost,&time);
node temp;
temp.cost=cost;
temp.time=time;
temp.id=v2;
edge[v1].push_back(temp);
if(ow==)
{
temp.id=v1;
edge[v2].push_back(temp);
}
} void dij0() // deug
{
int vis[maxn];
int pre[maxn];
int cost[maxn];
cost[s]=;
pre[s]=-;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++) d0[i]=inf;
d0[s]=;
while()
{
int v=-;
for(int i=;i<=n;i++)
{
if(vis[i]== && ( v==- || d0[v] > d0[i])) v=i;
}
if(v==-) break;
vis[v]=;
int len=edge[v].size();
for(int i=;i<len;i++)
{
node temp=edge[v][i];
if(vis[temp.id] == )
{
if(d0[temp.id] > d0[v]+temp.time )
{
d0[temp.id]=d0[v]+temp.time; //
pre[temp.id]=v;
cost[temp.id]=cost[v]+temp.cost;
}
else if(d0[temp.id] == d0[v]+temp.time)
{
if(cost[temp.id] > cost[v]+temp.cost)
{
cost[temp.id]=cost[v]+temp.cost;
pre[temp.id]=v;
}
} }
}
}
// cout<<"1"<<endl;
int zz=e;
line0.push_back(e);
while(pre[zz]!=-) //
{
line0.push_back(pre[zz]);
zz=pre[zz];
// cout<<zz<<endl;
}
//cout<<"2"<<endl; reverse(line0.begin(),line0.end());
} void dij1() // deug
{
int vis[maxn];
int pre[maxn];
int cost[maxn];
cost[s]=;
pre[s]=-;
memset(vis,,sizeof(vis));
// vis[s]=1;
for(int i=;i<=n;i++) d1[i]=inf;
d1[s]=;
while()
{
int v=-;
for(int i=;i<=n;i++)
{
if(vis[i]== && (v==- || d1[v] > d1[i])) v=i;
}
if(v==-) break;
vis[v]=;
// line1.push_back(v);
int len=edge[v].size();
for(int i=;i<len;i++)
{
node temp=edge[v][i];
if(vis[temp.id]==)
{
if(d1[temp.id] > d1[v]+temp.cost)
{
d1[temp.id]=d1[v]+temp.cost; //
pre[temp.id]=v;
cost[temp.id]=cost[v]+;
}
else if(d1[temp.id] == d1[v]+temp.cost)
{
if(cost[temp.id] > cost[v]+)
{
cost[temp.id]=cost[v]+;
pre[temp.id]=v;
}
}
} }
} int zz=e; // route
line1.push_back(e);
while(pre[zz]!=-)
{
line1.push_back(pre[zz]);
zz=pre[zz];
} reverse(line1.begin(),line1.end());
}
int check()
{
int len1=line1.size();
int len0=line0.size();
if(len1 != len0) return ;
for(int i=;i<len1;i++)
{
if(line0[i] != line1[i]) return ;
}
return -;
} int main()
{
cin>>n>>m;
while(m--) build_map();
cin>>s>>e;
dij0();// 0 refers to the shortest time
dij1();// 1 refers to the shortset cost
if(check() == ) // diff
{
printf("Time = %d: ",d0[e]);
cout<<line0[];
for(int i=;i<line0.size();i++) cout<<" => "<<line0[i];
cout<<endl; printf("Distance = %d: ",d1[e]);
cout<<line1[];
for(int i=;i<line1.size();i++) cout<<" => "<<line1[i];
cout<<endl;
}
else
{
printf("Time = %d; ",d0[e]);
printf("Distance = %d: ",d1[e]);
cout<<line1[];
for(int i=;i<line1.size();i++) cout<<" => "<<line1[i];
cout<<endl;
}
return ;
}

pat天梯赛练习集合 L3-007 天梯地图的更多相关文章

  1. PAT 天梯赛 L2-005 集合相似度

    set的应用 题目链接 题解 有点像集合的交并操作,直接利用set进行处理,因为set有去重的功能,而且set是利用红黑树实现的,查找速度快O(logN). 代码如下: #include<cst ...

  2. PAT天梯赛L2-005 集合相似度

    题目链接:点击打开链接 给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的 ...

  3. PAT 天梯赛 L2-005. 集合相似度 【SET】

    题目链接 https://www.patest.cn/contests/gplt/L2-005 思路 因为集合中的元素 是不重复的 所以用SET 来保存 集合 然后最后 查找一下 两个集合中共有元素 ...

  4. 天梯赛 L2-005 集合相似度 (set容器)

    给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...

  5. 天梯赛 - L2-005 集合相似度

    题目链接:https://www.patest.cn/contests/gplt/L2-005 这个题理解是个大问题啊,“给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合 ...

  6. PAT天梯赛 L1-049 天梯赛座位分配

    题目链接:点击打开链接 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] ...

  7. PAT L1 049 天梯赛座位分配

    天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位 ...

  8. PAT天梯赛L3-007 天梯地图

    题目链接:点击打开链接 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校所在地和赛场地点后,该地图应该推荐两条路线:一条是最快到达路线:一条是最短距离的路线.题目保证对任意的查询请求,地图上都至 ...

  9. pat 团体天梯赛 L3-007. 天梯地图

    L3-007. 天梯地图 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校 ...

随机推荐

  1. Learning Conditioned Graph Structures for Interpretable Visual Question Answering

    Learning Conditioned Graph Structures for Interpretable Visual Question Answering 2019-05-29 00:29:4 ...

  2. 8款超好用的SVG编辑工具用起来

    随着响应式网页的发展,对于内容呈现的要求也越来越高,尤其是图像.为了在各种设备上能实现自然伸缩或扩展而不影响图片质量,所以矢量图形(SVG)正变得越来越受欢迎. 大家都知道,在计算机图形学中,有两种主 ...

  3. 【转】asp获取【微信公众平台】Access Token的源代码下载

    在做微信开发时候,经常要用到Access Token,但是官网提供的都是基于php写的,我用asp写了,有需要可以直接复制去用,模板消息,jdk上传图片,客服消息等全需要这个:'获取 access_t ...

  4. Tekla 导出ifc并浏览

    Tekla导出IFC

  5. datax实例——全量、增量同步

    一.全量同步 本文以mysql -> mysql为示例: 本次测试的表为mysql的系统库-sakila中的actor表,由于不支持目的端自动建表,此处预先建立目的表: CREATE TABLE ...

  6. windows10 环境下的RabbitMQ安装步骤(图文)

    第一步:下载并安装erlang 原因:RabbitMQ服务端代码是使用并发式语言Erlang编写的,安装Rabbit MQ的前提是安装Erlang. 下载地址:http://www.erlang.or ...

  7. LeetCode_303. Range Sum Query - Immutable

    303. Range Sum Query - Immutable Easy Given an integer array nums, find the sum of the elements betw ...

  8. 什么是 https ?这应该是全网把 https 讲的最好的一篇文章了

    https://blog.csdn.net/m0_37907797/article/details/102759257

  9. robot:接口入参为图片时如何发送请求

    https://www.cnblogs.com/changyou615/p/8776507.html 接口是上传图片,通过F12抓包获得如下信息 由于使用的是RequestsLibrary,所以先看一 ...

  10. NGUI无法显示

    早上起来发现 ,NGUI无法显示,后来发现是场景Camera的 depth =0 : 要设置depth=-1. 原来相机之间也有渲染层级