当前位置:网站首页>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;
}
边栏推荐
- Have a part of the game, after NFT is disabled in my world
- 少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
- JWT 登录认证 + Token 自动续期方案,写得太好了!
- 合并表格行---三层for循环遍历数据
- One track education, PHP training, unity of knowledge and practice, popular
- Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
- 【C语言】结构体指针与结构体变量作形参的区别
- What is the optimization method of transaction and database
- Using auto.js to realize the function of fifaol3 mobile terminal card interceptor
- Resolve browser password echo
猜你喜欢

Guide for using IP phone system and VoIP system

Better and more modern terminal tools than xshell!

leetcdoe-342. 4的幂

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

Some thoughts on.Net desktop development

国产API管理工具Eolink太好用了,打造高效的研发利器

Three men "running away" from high positions in the mobile phone factory

二舅能治好年轻人的精神内耗吗?

持续(集成--&gt;交付--&gt;部署)

Can second uncle cure young people's spiritual internal friction?
随机推荐
[ecmascript6] symbol and its related use
今日睡眠质量记录75分
我抄底了被清算的NFT,却被OpenSea上了锁
leetcode-190.颠倒二进制位
Leetcode · daily question · 1331. array sequence number conversion · discretization
I miss the year of "losing" Li Ziqi
Redis - Basics
Parent and child of treeselect
国产API管理工具Eolink太好用了,打造高效的研发利器
【安全】 阅读 RFC6749 及理解 Oauth2.0 下的授权码模式
SQL每日一练(牛客新题库)——第4天:高级操作符
拒绝服务 DDoS 攻击
vim常用命令详解(vim使用教程)
【架构】评分较高的三本微服务书籍的阅读笔记
Today's sleep quality record 75 points
力扣 2354. 优质数对的数目
力扣 剑指 Offer 51. 数组中的逆序对
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
Table list filter results remain unchanged
不用Swagger,那我用啥?