当前位置:网站首页>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;
}边栏推荐
- 【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
- The underlying mechanism of advertising on websites
- Leetcode 213: looting II
- Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
- Technical dry goods Shengsi mindspire operator parallel + heterogeneous parallel, enabling 32 card training 242 billion parameter model
- Use of other streams
- Download address collection of various versions of devaexpress
- [Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
- Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire
- 项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
猜你喜欢

Dora (discover offer request recognition) process of obtaining IP address

Reconnaissance et détection d'images - Notes

Introduction of buffer flow

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

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

項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass

项目经验分享:基于昇思MindSpore实现手写汉字识别

Arduino Serial系列函数 有关print read 的总结

【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)

论文学习——鄱阳湖星子站水位时间序列相似度研究
随机推荐
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
Custom generic structure
Talk about floating
Arduino 软串口通信 的几点体会
Jeecg menu path display problem
技术干货|AI框架动静态图统一的思考
Rabbit MQ message sending of vertx
Es writing fragment process
圖像識別與檢測--筆記
Common analysis with criteria method
pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
Traversal in Lucene
【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结
Jeecg data button permission settings
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)
TypeScript let与var的区别
最全SQL与NoSQL优缺点对比
Topic | synchronous asynchronous
https://github.com/ZouJiu1/PAT