PAT (Advanced Level) Practise 1003. Emergency (25) Dijstra扩展应用

PAT (Advanced Level) L1-6. 连续因子 for循环暴力 L1-6. 连续因子 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个正整数N的因子中可能存在若干连续的数字。例如630可以分解为3*5*6*7,其中5、6、7就是3个连续的数字。给定任一正整数N, 阅读详情

1003. Emergency (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, 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 C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, 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


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 500, INF = 0x3f3f3f3f;
int N, M, C1, C2;
//men存储第i个节点有多少人,cou存储到当前节点相同长度最短路的条数
//d存储到节点i的最短距离,call存储到节点i能叫的最多的人数
int men[maxn + 5], mapp[maxn + 5][maxn + 5];
int cou[maxn + 5], d[maxn + 5], call[maxn + 5];
bool vis[maxn + 5];

void dijstra(int s) {
	memset(cou, 0, sizeof(cou));
	memset(call, 0, sizeof(call));
	memset(vis, false, sizeof(vis));
	call[s] = men[s];
	for (int i = 0; i < N; i++) {
		d[i] = mapp[s][i];
		if (mapp[s][i] < INF) {
			cou[i] = 1; //debug
			if (i != s) //debug 防止出现call[s] = call[s] + men[s]
				call[i] = call[s] + men[i];
		}
	}
	d[s] = 0;
	vis[s] = true;

	for (int t = 1; t <= N - 1; t++) {
		int minn = INF, index = s;
		for (int i = 0; i < N; i++) {
			if (!vis[i] && minn > d[i]) { //注意!vis[i]
				minn = d[i];
				index = i;
			}
		}
		vis[index] = true;
		for (int j = 0; j < N; j++) {
			if (!vis[j]) {
				//出现相同长度的最短路,则松弛call
				//若出现更短的路,则必须使得call[j] = call[index] + men[j]
				//因为先考虑路径最短然后才考虑尽可能多的人数
				if (d[j] == d[index] + mapp[index][j]) {
					cou[j] += cou[index]; //debug cou[j]++; 父节点那可能有很多相同长度的路,不能只加1
					if(call[j] < call[index] + men[j]) {
						call[j] = call[index] + men[j];
					}
				} else if(d[index] + mapp[index][j] < d[j]) {
					d[j] = d[index] + mapp[index][j];
					cou[j] = cou[index]; //debug cou[j] = 1; 父节点那可能有很多相同长度的路
					call[j] = call[index] + men[j];
				}
			}
		}
	}
}

int main()
{
	cin >> N >> M >> C1 >> C2;
	for (int i = 0; i < N; i++) {
		scanf("%d", &men[i]);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) {
				mapp[i][j] = 0;
			} else {
				mapp[i][j] = INF;
			}
		}
	}
	for (int t = 0; t < M; t++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		mapp[u][v] = mapp[v][u] = w;
	}
	if (C1 == C2) {
		printf("%d %d\n", 1, men[C1]);
		return 0;
	}
	dijstra(C1);
	printf("%d %d\n", cou[C2], call[C2]);
	return 0;
}





团体程序设计天梯赛-练习集 L2-2. 链表去重 数组模拟链表 L2-2. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点。即对任意键值K,只有键值或其绝对值等于K的第一个 阅读详情

相关推荐

可信数据空间:可信空间、区域功能节点、业务功能节点、连接器的关联关系

可信数据空间通过分层架构实现安全数据共享:可信空间作为顶层制定全局规则;区域功能节点协调辖区内功能节点协作;功能节点提供具体数据服务;连接器作为唯一通信通道确保安全交互。系统采用"规则自上而下约束,数据自下而上流动"机制,通过分层治理和标准化连接,在保证数据主权的同时实现跨域协作,具有策略分级执行、去中心化治理等特性,支持灵活扩展业务场景。

友莘居士的博客 1709

【PAT 1003】 Emergency 图论Dijkstra

1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, yo

天堂人间 5161

【GNSS/Linux】BKG Ntrip Client (BNC) 的编译与安装

【GNSS/Linux】BKG Ntrip Client (BNC) 的编译与安装 1. BNC软件 1.1 软件介绍 The BKG Ntrip Client (BNC) is an Open Source multi-stream client program designed for a variety of real-time GNSS applications. It was primarily designed for receiving data streams from any Ntrip

小马甲的新马甲 7826

1003. Emergency (25)

时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, you are given a special map of your country. The ma...

weixin_30915275的博客 206

Python-OPCUA 实现西门子PLC数据批量读写与自动化监控

本文详细介绍了如何使用Python结合OPC UA协议,实现对西门子PLC数据的批量读写与自动化监控。通过搭建开发环境、利用KEPserverEX作为通信桥梁,并配合Python代码实战,读者可以掌握高效的数据采集、批量写入以及构建带报警功能的监控系统的方法,从而大幅提升工业自动化场景下的数据处理效率和系统灵活性。

www00的博客 195

【WRF数据准备】气象驱动数据-ERA5再分析数据(Copernicus)

【WRF数据准备】气象驱动数据-ERA5再分析数据

WW、forever的博客 5560

1003. Emergency (25)-PAT

1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, yo

兵临城下 1786

SpringBoot 系列教程(十二):给大家推荐20个SpringBoot开源项目,私活必备

基于 SpringBoot2.x + Shiro 实现了用户管理、个人微信、支付宝支付,内置扫码支付、后台回调、订单查询、限流等一系列功能

Thinkingcao的专栏 2850

1003. Emergency (25) DFs

1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, you are given a sp

qwesde 600

Qt c++ llama.cpp 运行 LLaMA-3-8B 中文对话机器人(多模态输入)

助手:

寒寒豆豆软件公司的博客 231

麒麟服务器操作系统QT系列软件工具手册

对Qt提供的开发工具进行了一系列的优化之后,在日常的修复bug和维护框架的过程中,桌面研发对Qt的基础软件库也进行了部分优化工作,包括qtbase、qtwayland、qtscript、qt4-x11等Qt基础组件,涉及的Qt框架版本主要涉及到5.9和5.12两个版本。qt 的翻译,是由 ts 文件生成 qm 文件然后进行翻译,国产操作系统上qt 的翻译是由单独的qttranslations包中进行维护,其次部分汉化问题也是qt组件维护工作的一部分,qt的翻译机制如图4-7所示。

太极淘的博客 548

团体程序设计天梯赛-练习集 L2-018. 多项式A除以B 模拟

L2-018. 多项式A除以B 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这仍然是一道关于A/B的题,只不过A和B都换成了多项式。你需要计算两个多项式相除的商Q和余R,其中R的阶数必须小于B的阶数

EventQueue的博客 2514

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

团体程序设计天梯赛-练习集 L2-006 树的遍历 根据后序中序建树+BFS

L2-006. 树的遍历 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列。这里假设键值都是互不相等的正整数。 输入格式: 输入第

EventQueue的博客 2221

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

团体程序设计天梯赛-练习集 L2-3. 月饼 贪心

L2-3. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计

EventQueue的博客 1761

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

团体程序设计天梯赛-练习集 L2-005 集合相似度 STL set集合的交和并

L2-005. 集合相似度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不

EventQueue的博客 1427

团体程序设计天梯赛-练习集 L2-4. 这是二叉搜索树吗? 区间递归

L2-4. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值;

EventQueue的博客 1184

团体程序设计天梯赛-练习集 L2-1. 紧急救援 Dijstra单源最短路径拓展应用

L2-1. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数

EventQueue的博客 1155

PAT (Advanced Level) Practise 1114 Family Property (25) 并查集orDFS

1114. Family Property (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This time, you are supposed to help us col

EventQueue的博客 972

团体程序设计天梯赛-练习集 L2-014. 列车调度 构造非递减数列二分查找

L2-014. 列车调度 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 火车站的列车调度铁轨的结构如下图所示。 Figure 两端分别是一条入口(Entrance)轨道和一条出口(Exit

EventQueue的博客 941

PAT (Advanced Level) Practise 1109. Group Photo (25) 结构体排序

1109. Group Photo (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Formation is very important when taking a grou

EventQueue的博客 934

pat甲级 1020. Tree Traversals map递归建树 + BFS

先用map建立一棵二叉树,mr存右孩子节点,ml存左孩子节点,然后输出BFS路径就行了 #include #include #include #include #include using namespace std; int N; int po[35], in[35], prin[35]; int root, ip, len; map ml, mr; int solve

EventQueue的博客 903

团体程序设计天梯赛 L3-007. 天梯地图 Dijkstra

L3-007. 天梯地图 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校所在地和赛场地点后,该地图应该推荐两条路线:一条是最快到达路线;一条是最短

EventQueue的博客 887

PAT (Advanced Level) Practise 1111. Online Map (30) Dijstra单源最短路

1111. Online Map (30) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Input our current position and a destination, a

EventQueue的博客 804
上一篇: codeforces 676C Vasya and String 前缀数组+二分查找
下一篇: pat PAT (Advanced Level) Practise 1007. Maximum Subsequence Sum (25)
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址