当前位置:网站首页>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
- Common analysis with criteria method
- C code production YUV420 planar format file
- [coppeliasim4.3] C calls UR5 in the remoteapi control scenario
- List exercises after class
- 哪一刻你才发现青春结束了
- What did the DFS phase do
- Some basic operations of reflection
- 2021-07-18
- The difference between typescript let and VaR
猜你喜欢

HCIA notes

图像识别与检测--笔记

《指环王:力量之戒》新剧照 力量之戒铸造者亮相

Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS

专题 | 同步 异步

Qtip2 solves the problem of too many texts

Leetcode 213: looting II

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

Technical dry goods Shengsi mindspire operator parallel + heterogeneous parallel, enabling 32 card training 242 billion parameter model

Map interface and method
随机推荐
Unified handling and interception of exception exceptions of vertx
Visit Google homepage to display this page, which cannot be displayed
Industrial resilience
Common architectures of IO streams
Lucene skip table
VMWare网络模式-桥接,Host-Only,NAT网络
Partage de l'expérience du projet: mise en œuvre d'un pass optimisé pour la fusion IR de la couche mindstore
Leetcode 198: 打家劫舍
技术干货|关于AI Architecture未来的一些思考
最全SQL与NoSQL优缺点对比
Vertx's responsive redis client
c语言指针的概念
Shengsi mindspire is upgraded again, the ultimate innovation of deep scientific computing
PgSQL converts string to double type (to_number())
TreeMap
Jeecg request URL signature
Why is data service the direction of the next generation data center?
《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
The embodiment of generics in inheritance and wildcards
https://github.com/ZouJiu1/PAT