当前位置:网站首页>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;
}
边栏推荐
- Can second uncle cure young people's spiritual internal friction?
- Li Kou sword finger offer 51. reverse order pairs in the array
- Redis - Basics
- Jenkins -- continuous integration server
- Facial expression recognition based on pytorch convolution - graduation project "suggestions collection"
- Better and more modern terminal tools than xshell!
- 少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
- 不用Swagger,那我用啥?
- Table list filter results remain unchanged
- Operator3-设计一个operator
猜你喜欢

Can second uncle cure young people's spiritual internal friction?

Guide for using IP phone system and VoIP system

我抄底了被清算的NFT,却被OpenSea上了锁

夜神模拟器抓包微信小程序

Today's sleep quality record 75 points

MySQL 实践篇 —— 主从复制

jar包

Intra prediction and transform kernel selection based on Neural Network

半波整流点亮LED

Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development
随机推荐
Leetcode notes 566. Reshaping the matrix
[ecmascript6] symbol and its related use
Operator3-设计一个operator
docker部署mysql 实现远程连接[通俗易懂]
性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...
力扣 剑指 Offer 51. 数组中的逆序对
PHP生成随机数(昵称随机生成器)
Debezium系列之:2.0.0.Beta1的重大变化和新特性
Table list filter results remain unchanged
Better and more modern terminal tools than xshell!
Leetcode 笔记 118. 杨辉三角
You have to apologize if you get involved in the funny shop?
要想组建敏捷团队,这些方法不可少
leetcode-190.颠倒二进制位
Kotlin learning notes 3 - lambda programming
剖析 kubernetes 集群内部 DNS 解析原理
【C语言】结构体指针与结构体变量作形参的区别
Dry goods -- encapsulated anti shake and throttling method in the project
拒绝服务 DDoS 攻击
Redis - Basics