当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
技术干货|AI框架动静态图统一的思考
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
How long is the fastest time you can develop data API? One minute is enough for me
【MySQL 12】MySQL 8.0.18 重新初始化
Introduction of buffer flow
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Common architectures of IO streams
Common methods of file class
IO stream system and FileReader, filewriter
Introduction of transformation flow
随机推荐
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
《指环王:力量之戒》新剧照 力量之戒铸造者亮相
OSI knowledge sorting
Vertx's responsive redis client
Topic | synchronous asynchronous
Some experiences of Arduino soft serial port communication
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Application of pigeon nest principle in Lucene minshouldmatchsumscorer
Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估
IPv4 address
项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
Lucene introduces NFA
Grpc message sending of vertx
【MySQL 11】怎么解决MySQL 8.0.18 大小写敏感问题
Reconnaissance et détection d'images - Notes
Unified handling and interception of exception exceptions of vertx
Lucene merge document order