当前位置:网站首页>DOJP1520星门跳跃题解
DOJP1520星门跳跃题解
2022-07-28 12:37:00 【bj_hacker】
题目
链接
https://deeplearning.org.cn/problem/P1520
字面描述
描述
在 EVE 游戏中,宇宙被划分成为许多区域,每个区域中都有数目不定的星门,可以通过星门来跳跃到特定的区域(星门是双向的)。
现在你正参与 BBE 联军与 MLGBD 联盟的会战,但由于飞船受损,需要尽快回到后方的友军空间站进行维护。
试编写程序,计算出所须的最短的返回空间站时间。
为了简化问题,我们约定飞船所在的位置为区域 1,空间站所在的位置为区域 N。
输入描述
第1行,两个整数N,M,分别为区域的总数和星门的总数;
第2…M+1行,每行三个整数X[i],Y[i],Z[i],分别为星门连接的两个区域,以及跳跃所需时间;
输出描述
一个整数,返回空间站所需的最短时间。
用例输入 1
5 3
1 4 5
4 5 1
1 2 7
用例输出 1
6
用例输入 2
10 11
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
1 5 7
6 9 3
用例输出 2
28
提示
对于80%的数据,1<N<=10000,1<M<50000;
对于100%的数据,1<N≤30000,1<M<150000,1≤X[],Y[]≤N,1≤Z[]≤4096;
代码实现
#include<bits/stdc++.h>
using namespace std;
const int maxn=6e4+10;
const int maxm=3e5+10;
int n,m,cnt;
int head[maxn],dis[maxn];
bool vis[maxn];
struct node{
int v,w,nxt;
}e[maxm];
inline void add(int u,int v,int w){
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].nxt=head[u];
head[u]=cnt;
}
inline void Dijkstra(int u){
queue<int>q;
memset(dis,0x3f,sizeof(dis));
dis[u]=0;
vis[u]=true;
q.push(u);
while(!q.empty()){
int x=q.front();
q.pop();
vis[x]=false;
for(int i=head[x];i;i=e[i].nxt){
if(dis[e[i].v]>dis[x]+e[i].w){
dis[e[i].v]=dis[x]+e[i].w;
if(!vis[e[i].v]){
vis[e[i].v]=true;
q.push(e[i].v);
}
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
Dijkstra(1);
printf("%d\n",dis[n]);
return 0;
}
边栏推荐
- Humiliation, resistance, reversal, 30 years, China should win Microsoft once
- 111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
- 【C语言】结构体指针与结构体变量作形参的区别
- Org.apache.ibatis.exceptions.toomanyresultsexception
- 半波整流点亮LED
- C语言:随机生成数+归并排序
- 夜神模拟器抓包微信小程序
- 火山石投资章苏阳:硬科技,下一个10年相对确定的答案
- [error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088
- 记一次使用pdfbox解析pdf,获取pdf的关键数据的工具使用
猜你喜欢

Auto.js enables Taobao to quickly submit orders

【ECMAScript6】Promise

Night God simulator packet capturing wechat applet

Realize the mutual value transfer between main window and sub window in WPF

沾上趣店,都得道歉?

接口调不通,如何去排查?没想到10年测试老鸟栽在这道面试题上

Chapter 6 promotion

Excellent performance! Oxford, Shanghai, AI Lab, Hong Kong University, Shangtang, and Tsinghua have joined forces to propose a language aware visual transformer for reference image segmentation! Open

用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历

Can second uncle cure young people's spiritual internal friction?
随机推荐
夜神模拟器抓包微信小程序
Guide for using IP phone system and VoIP system
gicv3 spi register
Resolve browser password echo
Debezium series: major changes and new features of 2.0.0.beta1
Paddleclas classification practice record
Jenkins -- continuous integration server
屈辱、抗争、逆转,三十年,中国该赢微软一次了
Leetcode notes 118. Yang Hui triangle
Excellent performance! Oxford, Shanghai, AI Lab, Hong Kong University, Shangtang, and Tsinghua have joined forces to propose a language aware visual transformer for reference image segmentation! Open
国产口服新冠药阿兹夫定安全吗?专家权威解读
拥有游戏的一部分,写在我的世界禁用NFT之后
《暗黑破坏神4》PS4/PS5测试版已加入PlayStation数据库
Shell basic concepts and variables
[C language] the difference between structure pointer and structure variable as formal parameters
.NET的求复杂类型集合的差集、交集、并集
MySQL 实践篇 —— 主从复制
微念“失去”李子柒的这一年
[ecmascript6] symbol and its related use
Leetcode notes 566. Reshaping the matrix