当前位置:网站首页>1030 Travel Plan (30 分)
1030 Travel Plan (30 分)
2022-07-22 10:33:00 【学编程的蒟蒻】
1030 Travel Plan (30 分)
思路有空更新
#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]);
}
边栏推荐
- LeetCode912——sort an array—— quick sort algorithm
- Typora download and simple use tutorial
- LeetCode146——LRU Cache——DS Design
- When using CV2 to realize face recognition, Chinese is displayed on the recognition frame
- 7-3 Size of Military Unit (25 分)
- Websites jump inexplicably. What is website hijacking from Baidu? How to solve Baidu snapshot hijacking
- Kubernetes基础
- 她力量系列四丨读博6年两次换导师,靠一点点“倔”,俞舟成为social chatbot的开拓者之一
- 她力量系列八丨陈丹琦:我希望女生能够得到更多的机会,男生和女生之间的gap会逐渐不存在的
- redission扣库存demo
猜你喜欢
Statistical analysis of offline log collection
dns 劫持什么意思、dns 劫持原理及几种解决方法
她力量系列七丨兰艳艳:理想温暖10年科研路,女性可以柔和,更要自信、专业 | 妇女节特辑
Her power series five Zhu Haiyi: people oriented, building AI values
docker安装3主3从redis集群
CPU affinity
Causal learning weekly, issue 10: introduction to the latest causal discovery related papers in iclr2022
Core concepts of elastic search learning Introduction (4)
iptables实现负载均衡
How to repair DNS hijacking perfectly? How to solve DNS hijacking and how to repair it perfectly
随机推荐
What is network hijacking? How to repair web pages that have been tampered with and hijacked (final scheme) how to repair web page hijacking?
YOLO v1、v2、v3
The setting of node.master and node.data in the production environment of the introduction to elastic search (3)
通过@Autowired注入的bean,即使这个类上没有标注@Comment等这一类的注解,但是这个bean依然能够注入进来
Comment le détournement de DNS peut - il être parfaitement réparé? Comment résoudre le problème du détournement de DNS
笔记:C语言
Introduction to machine learning: Logistic regression-2
修改QtCreater界面大小
linux安装oracle XE
iptables实现负载均衡
IDEA 隐藏.idea文件夹 隐藏.iml文件
LeetCode103——zigzagLevelOrder of binary tree
她力量系列六丨杨笛一:女孩长大后数理化可以很好,科研可以很鲜活
Don't hack the website. How to solve it? How to deal with the problem of website being hacked
Kubernetes基础
Chen Danqi: I hope girls can get more opportunities, and the gap between boys and girls will gradually disappear
sql优化技巧及注意事项
她力量系列七丨兰艳艳:理想温暖10年科研路,女性可以柔和,更要自信、专业 | 妇女节特辑
LeetCode146——LRU Cache——DS Design
IDEA下载源码查看