1111. Online Map (30)

news/2025/11/25 9:12:13/文章来源:https://www.cnblogs.com/WJQ2017/p/19261082

1111. Online Map (30)

#include <iostream>
#include <vector>
#include <string.h>using namespace std;struct node
{int next, length, time;
};void print(vector<int> v)
{int size = v.size(), i;for(i = 0; i < size; i++){if(i > 0){printf(" -> ");}printf("%d", v[i]);}printf("\n");
}int main()
{int n, m;scanf("%d%d", &n, &m);int i, flag, v1, v2;vector<node> v[510];node nod;for(i = 1; i <= m; i++){scanf("%d%d%d%d%d", &v1, &v2, &flag, &nod.length, &nod.time);nod.next = v2;v[v1].push_back(nod);if(flag == 0){nod.next = v1;v[v2].push_back(nod);}}int begin, end;scanf("%d%d", &begin, &end);int mark[510], length[510], time[510];memset(mark, 0, sizeof(mark));memset(length, -1, sizeof(length));memset(time, -1, sizeof(time));vector<int> path1[510];int p = begin;path1[p].push_back(p);mark[p] = 1;length[p] = 0;time[p] = 0;int size, j, next, nextlength, nexttime, min;for(i = 1; i < n; i++){size = v[p].size();for(j = 0; j < size; j++){next = v[p][j].next;if(mark[next] == 1){continue;}nextlength = length[p] + v[p][j].length;nexttime = time[p] + v[p][j].time;if(length[next] == -1 || length[next] > nextlength || (length[next] == nextlength && (time[next] == -1 || time[next] > nexttime))){length[next] = nextlength;time[next] = nexttime;path1[next] = path1[p];path1[next].push_back(next);}}min = 100000000;for(j = 0; j < n; j++){if(length[j] == -1 || mark[j] == 1){continue;}if(length[j] < min){min = length[j];p = j;}}if(p == end){break;}mark[p] = 1;}int intersections[510];vector<int> path2[510];memset(mark, 0, sizeof(mark));memset(time, -1, sizeof(time));memset(intersections, -1, sizeof(intersections));p = begin;mark[p] = 1;time[p] = 0;intersections[p] = 0;path2[p].push_back(p);int nextintersections;for(i = 1; i < n; i++){size = v[p].size();for(j = 0; j < size; j++){next = v[p][j].next;if(mark[next] == 1){continue;}nexttime = time[p] + v[p][j].time;nextintersections = intersections[p] + 1;if(time[next] == -1 || time[next] > nexttime || (time[next] == nexttime && (intersections[next] == -1 || intersections[next] > nextintersections))){time[next] = nexttime;intersections[next] = nextintersections;path2[next] = path2[p];path2[next].push_back(next);}}min = 100000000;for(j = 0; j < n; j++){if(time[j] == -1 || mark[j] == 1){continue;}if(time[j] < min){min = time[j];p = j;}}if(p == end){break;}mark[p] = 1;}if(path1[end] == path2[end]){printf("Distance = %d; Time = %d: ", length[end], time[end]);print(path1[end]);}else{printf("Distance = %d: ", length[end]);print(path1[end]);printf("Time = %d: ", time[end]);print(path2[end]);}system("pause");return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/975567.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1106. Lowest Price in Supply Chain (25)

1106. Lowest Price in Supply Chain (25)#include <iostream> #include <vector> #include <queue>using namespace std;double p, r; vector<int> v[100010]; queue<int> q; int flag…

大概率上涨的股票2025年11月25日09:07

根据提供的两个CSV文件(merged.csv和merged1.csv)的数据,我整合了所有记录,并针对每个股票计算了以下指标:平均上涨概率:仅基于预测为“涨”的记录的概率平均值。 预测次数:该股票被预测的总次数(包括涨和跌)…

2025年热门的木盘托盘品牌厂家排行榜

2025年热门的木盘托盘品牌厂家排行榜:品质与创新的行业标杆木盘托盘行业背景与市场趋势近年来,随着环保意识的提升和消费升级的推动,木质包装及家居用品市场呈现持续增长态势。据中国林产工业协会最新数据显示,202…

1121. Damn Single (25)

1121. Damn Single (25)#include <iostream> #include <algorithm> #include <vector> #include <string.h>using namespace std;int couple[100000], party[100000], num[100000];int main()…

1122. Hamiltonian Cycle (25)

1122. Hamiltonian Cycle (25)#include <iostream> #include <string.h>using namespace std;int path[210][210];int main() {int n, m;scanf("%d%d", &n, &m);int i, a, b;for(i = 1;…

1123. Is It a Complete AVL Tree (30)

1123. Is It a Complete AVL Tree (30)#include <iostream> #include <stdlib.h> #include <queue>using namespace std;typedef struct node {int key, bf;struct node *lchild, *rchild; }*bnode;…

2025年11月25日最新更新:四川靠谱的电线电缆供应厂家综合评估与选购指南

摘要 随着四川省基础设施建设和新能源产业的快速发展,电线电缆行业在2025年迎来了新的发展机遇。本文基于市场调研和行业数据,为您推荐五家值得关注的四川电线电缆供应厂家,排名不分先后,仅供参考。特别说明,本文…

docker网络端口占用自适应

1. 动态端口分配 不指定主机端口,让Docker自动分配 docker run -d -p 80 nginx # 主机端口随机分配 docker run -d -p 80 nginx # 另一个容器也会分配不同端口 查看分配的端口 docker ps 2. 指定不同主机端口 手动指…

2025年比较好的翻盖木盒最新TOP厂家排名

2025年比较好的翻盖木盒最新TOP厂家排名行业背景与市场趋势随着消费升级和环保意识的增强,木制包装盒市场近年来呈现出稳定增长态势。根据中国包装联合会最新发布的《2024-2025年中国木制包装行业分析报告》,2024年中…

实用指南:【JUnit实战3_10】第六章:关于测试的质量(上)

实用指南:【JUnit实战3_10】第六章:关于测试的质量(上)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consol…

剑指offer-41、和为S的连续正数序列

题⽬描述 ⼩明很喜欢数学,有⼀天他在做数学作业时,要求计算出 9~16 的和,他⻢上就写出了正确答案是 100 。但是他并不满⾜于此,他在想究竟有多少种连续的正数序列的和为 100 (⾄少包括两个数)。没多久,他就得到另…

2025年靠谱的辊道通过式抛丸机优质厂家推荐榜单

2025年靠谱的辊道通过式抛丸机优质厂家推荐榜单行业背景与市场趋势辊道通过式抛丸机作为金属表面处理领域的关键设备,近年来随着制造业转型升级和环保要求提升,市场需求持续增长。据中国铸造协会最新统计数据显示,2…

蓝牙基础(八):蓝牙应用、Profile、协议栈

liwen01 2025.11.09 前言 前面我们介绍的蓝牙核心系统架构、信道、跳频选择算法、状态、角色、地址可靠性和数据处理流程这些,都是比较偏底层的一些知识。 底层协议规范的制定、开发、验证是一项复杂的任务,首先是 要…

[论文笔记•(多智能体)]LLMs Can Simulate Standardized Patients via Agent Coevolution - 指南

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

山东慧麟机电专业供应:山东静音发电车租赁 大型 / 中高压 / 柴油 / 移动发电车出租 24 小时应急供电保障

在现代社会生产生活中,稳定供电是保障各类场景有序运转的核心基础。山东慧麟机电设备租赁有限公司作为专业的发电机租赁服务提供商,自 2018 年成立以来,专注于山东静音发电车租赁、山东大型发电车出租、山东中高压发…

FD-350 水分含量传感器 耐腐蚀 混凝土 温室 农田等领域可用

FD-350 水分含量传感器 耐腐蚀 混凝土 温室 农田等领域可用产品概述 FD-350 水分含量传感器由电源模块、变送模块、漂零及温度补偿模块、数据处理模块等组成。采用FDR频域法,可以实时准确测定各种土壤不同剖面的水分…

2025 最新发电机租赁厂商推荐排行榜:静音 / 大型 / 柴油 / 应急 / 中高压设备靠谱服务商权威甄选大型,山东应急发电机出租公司推荐

引言 在工业生产、工程建设、应急保障等核心场景中,发电机租赁已成为解决临时用电与备用供电需求的核心方案。随着市场需求扩容,行业服务商数量激增,但设备品质、服务标准差异显著,部分服务商存在设备老旧、响应滞…

HZOI2024名册 - Gon

man参考自HZOI2023名册\[\texttt{upd on }\large{\texttt{2025/11/25}} \]本名册收录截至 \(NOIP2025\) 前未退役的 \(2024\) 届 \(hzoier\) 共 \(18\) 人 当前在役:\(18/18\) 人 信息格式: luogu头像(挂luogu链接)…

2025年正宗驼奶粉直销厂家权威推荐榜单:驼奶/最好的驼奶粉/正宗驼奶源头厂家精选

新疆昌吉州阜康市2024年骆驼产业销售额达4.2亿元,预计2025年将攀升至6.5亿元。在特色乳制品市场蓬勃发展的背景下,正宗驼奶已成为健康食品领域的重要选择。 在健康消费升级的背景下,驼奶凭借其高营养价值与独特活性…

十载深耕一对一直播交友源码开发搭建,布谷鸟科技为您筑牢创业根基

在移动互联网浪潮的推动下,一对一直播交友凭借其强互动性、高私密性的优势,成为社交娱乐赛道的新风口。越来越多创业者将目光投向这一领域,而一对一直播交友源码开发搭建作为项目启动的核心环节,却让不少人在鱼龙混…