当前位置:网站首页>Dojp1520 gate jumping problem solution
Dojp1520 gate jumping problem solution
2022-07-28 13:49:00 【bj_ hacker】
DOJP1520 Stargate jumping problem solution
subject
link
https://deeplearning.org.cn/problem/P1520
Literal description
describe
stay EVE In the game , The universe is divided into many regions , There are an indefinite number of stargates in each area , You can jump to a specific area through the Stargate ( The Stargate is bidirectional ).
Now you are participating BBE Coalition forces and MLGBD The battle of the alliance , But because the spacecraft was damaged , We need to return to the friendly space station in the rear as soon as possible for maintenance .
Try to write a program , Calculate the shortest time to return to the space station .
To simplify the problem , We agreed that the location of the spacecraft is the area 1, The space station is located in the area N.
Input description
The first 1 That's ok , Two integers N,M, They are the total number of regions and the total number of stargates ;
The first 2…M+1 That's ok , Three integers per row X[i],Y[i],Z[i], They are the two areas connected by the Stargate , And the time it takes to jump ;
Output description
An integer , The shortest time required to return to the space station .
Use case input 1
5 3
1 4 5
4 5 1
1 2 7
Use case output 1
6
Use case input 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
Use case output 2
28
Tips
about 80% The data of ,1<N<=10000,1<M<50000;
about 100% The data of ,1<N≤30000,1<M<150000,1≤X[],Y[]≤N,1≤Z[]≤4096;
Code implementation
#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;
}
边栏推荐
- 30 day question brushing plan (III)
- 30 day question brushing plan (IV)
- 111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
- C language: merge sort
- Analyzing the principle of DNS resolution in kubernetes cluster
- 国产API管理工具Eolink太好用了,打造高效的研发利器
- [C language] the difference between structure pointer and structure variable as formal parameters
- To build agile teams, these methods are indispensable
- Better and more modern terminal tools than xshell!
- Operator3-设计一个operator
猜你喜欢

After finishing, help autumn move, I wish you call it an offer harvester

Socket类关于TCP字符流编程的理解学习

Jenkins -- continuous integration server

Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree

No swagger, what do I use?

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

30 day question brushing plan (III)

How to play a data mining game entry Edition

You have to apologize if you get involved in the funny shop?

30 day question brushing training (I)
随机推荐
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
Lyscript get previous and next instructions
DOJNOIP201708奶酪题解
You have to apologize if you get involved in the funny shop?
[C language] the difference between structure pointer and structure variable as formal parameters
Cesium pit -- pit used by various API calls and API itself
算法---不同路径(Kotlin)
使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
My friend sent me some interview questions
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
C language: random number + quick sort
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses conflict function to give 95% confidence interval of regressi
DOJP1520星门跳跃题解
面经整理,助力秋招,祝你称为offer收割机
Beyond istio OSS -- current situation and future of istio Service Grid
C语言:随机生成数+归并排序
SQL daily practice (Niuke new question bank) - day 4: advanced operators
Uva11175 digraph D and E from D to e and back
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)