当前位置:网站首页>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;
}
边栏推荐
- What if the server cannot be connected (the original server cannot find the target resource)
- 力扣 剑指 Offer 51. 数组中的逆序对
- Leetcode-136. numbers that appear only once
- Night God simulator packet capturing wechat applet
- 倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
- 要想组建敏捷团队,这些方法不可少
- 【架构】评分较高的三本微服务书籍的阅读笔记
- 国产API管理工具Eolink太好用了,打造高效的研发利器
- 力扣 2354. 优质数对的数目
- LyScript 获取上一条与下一条指令
猜你喜欢
JWT 登录认证 + Token 自动续期方案,写得太好了!

Unity - "synthetic watermelon" small game notes

MySQL 实践篇 —— 主从复制

Guide for using IP phone system and VoIP system

Leetcode-190. inverting binary bits

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

【ECMAScript6】Promise

FFT海浪模拟

.NET桌面开发的一些思考

Chapter 6 promotion
随机推荐
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
微念“失去”李子柒的这一年
Guide for using IP phone system and VoIP system
Beyond istio OSS -- current situation and future of istio Service Grid
Leetcode 笔记 118. 杨辉三角
Why is crypto game changing the game industry?
JVM 内存管理 你知道多少
数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
2021-10-06
比XShell更好用、更现代的终端工具!
How does the vditor renderer achieve server-side rendering (SSR)?
GameStop熊市杀入NFT交易,老牌游戏零售商借Web3焕发第二春
C language: quick sorting of sequential storage structure
严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数
Jar package
How much do you know about JVM memory management
IP电话系统和VoIP系统使用指南
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
验证码暴力破解测试[通俗易懂]
Org.apache.ibatis.exceptions.toomanyresultsexception