当前位置:网站首页>PAT甲级 1030 Travel Plan
PAT甲级 1030 Travel Plan
2022-07-03 07:34:00 【九是否非随机的称呼】
迪杰特斯拉方式,要注意距离相同时,要判断costes并保存相应的路径
#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;
}边栏推荐
- Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
- Comparison of advantages and disadvantages between most complete SQL and NoSQL
- 技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
- TCP cumulative acknowledgement and window value update
- 1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- TreeMap
- 技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
- Vertx multi vertical shared data
- Arduino Serial系列函数 有关print read 的总结
- Technical dry goods Shengsi mindspire lite1.5 feature release, bringing a new end-to-end AI experience
猜你喜欢

Shengsi mindspire is upgraded again, the ultimate innovation of deep scientific computing

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

《指環王:力量之戒》新劇照 力量之戒鑄造者亮相

Collector in ES (percentile / base)

The embodiment of generics in inheritance and wildcards

C code production YUV420 planar format file

技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建

昇思MindSpore再升级,深度科学计算的极致创新

带你全流程,全方位的了解属于测试的软件事故

URL programming
随机推荐
Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
Partage de l'expérience du projet: mise en œuvre d'un pass optimisé pour la fusion IR de la couche mindstore
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
The concept of C language pointer
Spa single page application
Various postures of CS without online line
Take you through the whole process and comprehensively understand the software accidents that belong to testing
为什么说数据服务化是下一代数据中台的方向?
Vertx multi vertical shared data
Vertx metric Prometheus monitoring indicators
Application of pigeon nest principle in Lucene minshouldmatchsumscorer
SQL create temporary table
【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
Vertx's responsive redis client
GStreamer ffmpeg avdec decoded data flow analysis
Custom generic structure
Qtip2 solves the problem of too many texts
https://github.com/ZouJiu1/PAT