当前位置:网站首页>Pat class a 1030 travel plan
Pat class a 1030 travel plan
2022-07-03 07:42:00 【IX. is it a non random title】
Dijietesla mode , Pay attention to the same distance , To judge costes And save the corresponding path
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char **argv){
int N, M, S, D, i, j, k, m, n, minmin;
cin>>N>>M>>S>>D;
int INFINF = 999999;
int cityhighway[N][N];
int costes[N][N];
memset((void *)cityhighway, INFINF, sizeof(int) * N * N);
memset((void *)costes, INFINF, sizeof(int) * N * N);
int status[N];
int way[N];
int dis[N];
int cos[N];
memset((void *)cos, INFINF, sizeof(int) * N);
memset((void *)dis, INFINF, sizeof(int) * N);
memset((void *)status, 0, sizeof(int) * N);
for(i = 0; i < M; i++){
cin>>m>>n>>k>>j;
cityhighway[m][n]=cityhighway[n][m]=k;
costes[n][m]=costes[m][n]=j;
}
dis[S] = 0;
cos[S] = 0;
way[S] = S;
status[S] = 0;
for(i = 0; i < N; i++){
minmin = 999998;
for(j = 0; j < N; j++){
if(minmin > dis[j] && status[j]==0){
minmin = dis[j];
k = j;
}
}
status[k] = 1;
for(j = 0; j < N; j++){
if((minmin + cityhighway[k][j]) < dis[j] && status[j]==0){
dis[j] = minmin + cityhighway[k][j];
cos[j] = cos[k] + costes[k][j];
way[j] = k;
}else if((minmin + cityhighway[k][j]) == dis[j] && status[j]==0){
if((cos[k] + costes[k][j]) < cos[j]){
dis[j] = minmin + cityhighway[k][j];
cos[j] = cos[k] + costes[k][j];
way[j] = k;
}
}
}
}
vector<int> pth;
k = way[D];
pth.push_back(D);
while(k!=S){
pth.push_back(k);
k = way[k];
}
pth.push_back(S);
reverse(pth.begin(), pth.end());
for(i = 0; i < pth.size(); i++) cout<<pth[i]<<" ";
cout<<dis[D]<<" "<<cos[D];
return EXIT_SUCCESS;
}边栏推荐
- 技术干货|百行代码写BERT,昇思MindSpore能力大赏
- Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
- Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
- VMware network mode - bridge, host only, NAT network
- Enter three times and guess a number
- SQL create temporary table
- Comparison of advantages and disadvantages between most complete SQL and NoSQL
- Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
- Traversal in Lucene
- 【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结
猜你喜欢

Analysis of the problems of the 7th Blue Bridge Cup single chip microcomputer provincial competition

技术干货|AI框架动静态图统一的思考

Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function

PAT甲级 1030 Travel Plan

Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task

The concept of C language pointer

Leetcode 213: looting II

Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition

HCIA notes

Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
随机推荐
Industrial resilience
Vertx metric Prometheus monitoring indicators
技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
Go language foundation ----- 02 ----- basic data types and operators
Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake
Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function
【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
Go language foundation ----- 11 ----- regular expression
VMware network mode - bridge, host only, NAT network
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
Vertx restful style web router
JUnit unit test of vertx
Vertx's responsive redis client
Structure of golang
昇思MindSpore再升级,深度科学计算的极致创新
PgSQL converts string to double type (to_number())
Go language foundation ----- 13 ----- file
Lucene introduces NFA
List exercises after class
Iterm2设置
https://github.com/ZouJiu1/PAT