当前位置:网站首页>1030 travel plan (30 points)
1030 travel plan (30 points)
2022-07-22 20:33:00 【Konjaku for learning programming】
1030 Travel Plan (30 branch )
Update ideas when available
#include <iostream>
#include <cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
int map[550][550], vis[550], dis[550], path[550];
int a[550][550], sum[550];
int n, m, S, D;
void dijkstra(int s){
memset(dis, inf, sizeof dis);
dis[s] = 0;
for(int i = 0; i < n; ++i){
int t = -1;
for(int j = 0; j < n; ++j)
if(!vis[j] && (t == -1 || dis[j] < dis[t]))
t = j;
vis[t] = 1;
for(int j = 0; j < n; ++j){
if(dis[j] > dis[t] + map[t][j]){
dis[j] = dis[t] + map[t][j];
sum[j] = sum[t] + a[t][j];
path[j] = t;
}
else if(dis[j] == dis[t] + map[t][j]){
if(sum[j] > sum[t] + a[t][j]){
sum[j] = sum[t] + a[t][j];
path[j] = t;
}
}
}
}
}
void dfs(int x){
if(x == S){
printf("%d", x);
return;
}
dfs(path[x]);
printf(" %d", x);
}
int main() {
cin >> n >> m >> S >> D;
memset(map, inf, sizeof map);
for(int i = 0; i < n; ++i)
map[i][i] = 0;
while(m--){
int x, y, z1, z2;
cin >> x >> y >> z1 >> z2;
map[x][y] = map[y][x] = z1;
a[x][y] = a[y][x] = z2;
}
dijkstra(S);
dfs(D);
printf(" %d %d", dis[D], sum[D]);
}
边栏推荐
猜你喜欢
随机推荐
Mysql连接失败解决方案
JSON output to file line by line in format
mysql索引
LeetCode32——next permutation
1053 Path of Equal Weight (30 分)
YOLO v1、v2、v3
Pytoch sets different learning rates at different levels
JDBC异常SQLException的捕获与处理
Kubernetes基础
Exclusive interview with Huang Hui, a scholar of women in AI: dream of drawing shapes and find the door to breakthrough
修改QtCreater界面大小
Introduction to machine learning: Logistic regression-2
专访Women in AI学者黄惠:绘图形之梦,寻突破之门
MySQL query blob
Classic cases of semaphore synchronization and mutual exclusion
她力量系列四丨读博6年两次换导师,靠一点点“倔”,俞舟成为social chatbot的开拓者之一
YOLO v1、v2、v3
她力量系列三丨把握当下,坚持热爱,与食物图像识别结缘的科研之路
Pytorch dynamically adjusts the learning rate, and the learning rate automatically decreases according to loss
LeetCode912——sort an array—— quick sort algorithm