当前位置:网站首页>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 | reproduce iccv2021 best paper swing transformer with Shengsi mindspire
- Analysis of the eighth Blue Bridge Cup single chip microcomputer provincial competition
- PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
- Logging log configuration of vertx
- 项目经验分享:基于昇思MindSpore,使用DFCNN和CTC损失函数的声学模型实现
- TCP cumulative acknowledgement and window value update
- Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
- Some basic operations of reflection
- 哪一刻你才发现青春结束了
- Common architectures of IO streams
猜你喜欢
随机推荐
TypeScript let与var的区别
II. D3.js draw a simple figure -- circle
截图工具Snipaste
Vertx multi vertical shared data
Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
Realize the reuse of components with different routing parameters and monitor the changes of routing parameters
Leetcode 198: house raiding
Common operations of JSP
Application of pigeon nest principle in Lucene minshouldmatchsumscorer
Some basic operations of reflection
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
VMWare网络模式-桥接,Host-Only,NAT网络
sharepoint 2007 versions
Vertx restful style web router
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
Lombok cooperates with @slf4j and logback to realize logging
Technical dry goods Shengsi mindspire lite1.5 feature release, bringing a new end-to-end AI experience
Lucene hnsw merge optimization
[set theory] order relation (partial order relation | partial order set | example of partial order set)
技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务