当前位置:网站首页>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;
}边栏推荐
- 【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结
- 【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
- 华为S5700交换机初始化和配置telnet,ssh用户方法
- Qtip2 solves the problem of too many texts
- 技术干货|百行代码写BERT,昇思MindSpore能力大赏
- Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
- C2 several methods of merging VCF files
- 技术干货|利用昇思MindSpore复现ICCV2021 Best Paper Swin Transformer
- Inverted chain disk storage in Lucene (pfordelta)
- JUnit unit test of vertx
猜你喜欢

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

Qtip2 solves the problem of too many texts

Hnsw introduction and some reference articles in lucene9

OSPF experiment

技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!

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

技术干货|百行代码写BERT,昇思MindSpore能力大赏

Understanding of class

研究显示乳腺癌细胞更容易在患者睡觉时进入血液

Robots protocol
随机推荐
项目经验分享:基于昇思MindSpore实现手写汉字识别
The babbage industrial policy forum
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
SQL create temporary table
华为交换机配置ssh登录远程管理交换机
OSPF protocol summary
Go language foundation ----- 06 ----- anonymous fields, fields with the same name
Go language foundation ----- 15 ----- reflection
C2 several methods of merging VCF files
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Go language foundation ----- 08 ----- interface
【MySQL 12】MySQL 8.0.18 重新初始化
Leetcode 213: 打家劫舍 II
Vertx restful style web router
图像识别与检测--笔记
Application of pigeon nest principle in Lucene minshouldmatchsumscorer
s7700设备如何清除console密码
技术干货|AI框架动静态图统一的思考
TypeScript let与var的区别
Iterm2设置
https://github.com/ZouJiu1/PAT