1003 Emergency

本文介绍了一个城市应急救援团队领导面临的挑战:如何在接到其他城市的紧急求救电话后,迅速带领团队到达现场并沿途召集尽可能多的救援人员。通过使用Dijkstra算法解决单源有权图最短路径问题,实现救援路线的快速规划。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input Specification:

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N(≤500)N (≤500)N(500) - the number of cities (and the cities are numbered from 0toN−10 to N−10toN1), MMM - the number of roads, C​1C​1C1​​ and C​2​​C​2​​C2 - the cities that you are currently in and that you must save, respectively. The next line contains NNN integers, where the iii-th integer is the number of rescue teams in the iii-th city. Then MMM lines follow, each describes a road with three integers c​1​​,c​2​​c​1​​, c​2​​c1,c2 and LLL, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C​1C​1C1​​ to C​2C​2C2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1C​1C1​​ and C​2C​2C2​​, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input:

5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output:

2 4


解题思路:

单源有权图最短路径问题,使用Dijkstra算法可解,详见代码


#include <iostream>
using namespace std;
#define INF 100000

int main()
{
	int city[501] = { 0 };	// 节点权重
	int road[501][501];		// 边权重
	bool visit[501] = { 0 };	
	int dist[501] = { 0 };		// 记录最短路径
	int weight[501] = { 0 };	// 记录最大权重和
	int num[501] = { 0 };		// 记录最短路径数量

	int N, M, C1, C2;
	int temp;
	scanf("%d%d%d%d", &N, &M, &C1, &C2);
	for (int i = 0; i < N; i++) {
		scanf("%d", &temp);
		city[i] = temp;
	}
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			road[i][j] = INF;		// 初始化
	int c1, c2, L;
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &c1, &c2, &L);
		road[c1][c2] = road[c2][c1] = L;	// 无向图
	}
	
	// 初始化
	for (int i = 0; i < N; i++) 
		dist[i] = road[C1][i];		
	dist[C1] = 0;
	weight[C1] = city[C1];
	num[C1] = 1;
	
	// 核心算法,与寻常Dijkstra算法有所差异 
	for (int i = 0; i < N; i++) {
		int V = -1;
		int MinDist = INF;
		for (int j = 0; j < N; j++) {
			if (visit[j] == false && dist[j] < MinDist) {
				MinDist = dist[j];
				V = j;
			}
		}
		if (V == -1)
			break;
		visit[V] = true;
		for (int W = 0; W < N; W++) {
			if (visit[W] == false && road[V][W] < INF) {
				if (dist[V] + road[V][W] < dist[W]) {
					dist[W] = dist[V] + road[V][W];
					num[W] = num[V];
					weight[W] = weight[V] + city[W];
				}
				else if (dist[V] + road[V][W] == dist[W]) {
					num[W] += num[V];
					if (weight[W] < weight[V] + city[W])
						weight[W] = weight[V] + city[W];
				}
			}
		}
	}
	printf("%d %d", num[C2], weight[C2]);
}
标题基于SpringBoot的蛋糕烘焙分享平台研究AI更换标题第1章引言介绍蛋糕烘焙分享平台的研究背景、意义、现状以及论文的方法和创新点。1.1研究背景与意义分析蛋糕烘焙行业的现状,阐述分享平台的重要性和意义。1.2国内外研究现状综述国内外在蛋糕烘焙分享平台方面的研究进展。1.3论文方法及创新点概述论文的研究方法,突出创新点。第2章相关理论介绍SpringBoot框架和分享平台开发的相关理论。2.1SpringBoot框架概述简述SpringBoot框架的特点、优势和应用场景。2.2分享平台技术基础阐述分享平台开发所需的技术基础,如前后端分离、数据库设计等。2.3用户行为分析理论介绍用户行为分析的基本理论和方法,为平台功能设计提供指导。第3章平台需求分析对蛋糕烘焙分享平台进行需求分析,明确平台功能和性能要求。3.1目标用户群体分析分析平台的目标用户群体,了解其需求和特点。3.2功能需求分析详细分析平台应具备的功能,如用户注册、烘焙教程发布、互动交流等。3.3性能需求分析对平台的性能要求进行分析,确保平台的稳定性和可扩展性。第4章平台设计根据需求分析结果,设计蛋糕烘焙分享平台的整体架构和详细功能。4.1平台架构设计设计平台的整体架构,包括前后端分离、数据库设计等。4.2功能模块设计详细设计平台的功能模块,如用户管理、内容管理、互动交流模块等。4.3数据库设计根据平台需求,设计合理的数据库表结构和数据字典。第5章平台实现与测试介绍平台的实现过程,包括环境搭建、编码实现和测试等环节。5.1环境搭建与配置搭建开发环境,配置必要的软件和工具。5.2编码实现按照设计要求,编写平台的前后端代码。5.3平台测试与优化对平台进行测试,发现并解决问题,优化平台性能。第6章结论与展望总结论文的研究成果,展望未来的研究方向和应用前景。6.1研究结论概括论文的主要研究内容和取得的成果。6.2未来研究
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值