【PAT - 甲级1003】Emergency (25分)(Dijkstra,最短路条数,双权值最短路)

题干:

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) - the number of cities (and the cities are numbered from 0 to N−1), M - the number of roads, C​1​​ and C​2​​ - 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 c​1​​, c​2​​ 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 C​1​​ to C​2​​.

Output Specification:

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

题目大意:

作为一个城市的紧急救援队队长,你会得到一份特殊的国家地图。这张地图显示了由一些道路连接起来的几个分散的城市。地图上标明了每个城市的救援队数量和每对城市之间的道路长度。当从其他城市接到紧急电话时,你的工作就是尽快把你的人带到那个地方,同时在路上尽可能多地召集人手。

一句话题意:给定一张无向图,给定起点和终点,点有点权,边有边权,求两点之间最短路条数,并求出在最短路的条件下路径的点权和的最大值。

解题报告:

不得不说,,,几年前的PAT考题确实比现在要难得多,这题虽然是裸题,但是代码量也不小了,竟然才是25分题。

直接Dijkstra搞双权值的就行,记得点编号是0~N-1的,所以要先转化到1~N。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
const int INF = 0x3f3f3f3f;
int n,m,st,ed,val[MAX];
struct Edge {int v,ne,w;
} e[MAX*2];
int head[MAX],tot;
void add(int u,int v,int w) {e[++tot].v = v;e[tot].w = w;e[tot].ne = head[u];head[u] = tot;
}
struct Point {int pos,c;Point(){}Point(int pos,int c):pos(pos),c(c){}bool operator<(const Point & b) const {return c > b.c; }
};
priority_queue<Point> pq; 
int dis[MAX],vis[MAX],ans[MAX],Max[MAX];
void Dij() {for(int i = 1; i<=n; i++) dis[i] = INF,vis[i] = 0,ans[i] = 0,Max[i] = 0;pq.push(Point(st,0)); dis[st] = 0; ans[st] = 1; Max[st] = val[st];while(pq.size()) {Point cur = pq.top();pq.pop();if(vis[cur.pos] == 1) continue;vis[cur.pos] = 1;for(int i = head[cur.pos]; ~i; i = e[i].ne) {int v = e[i].v;if(vis[v]) continue;if(dis[v] > dis[cur.pos] + e[i].w) {dis[v] = dis[cur.pos] + e[i].w;ans[v] = ans[cur.pos];Max[v] = Max[cur.pos] + val[v];pq.push(Point(v,dis[v]));}else if(dis[v] == dis[cur.pos] + e[i].w) {ans[v] += ans[cur.pos];Max[v] = max(Max[v],Max[cur.pos] + val[v]);}}}
}
int main()
{cin>>n>>m>>st>>ed; st++,ed++; for(int i = 1; i<=n; i++) cin>>val[i],head[i] = -1;for(int u,v,w,i = 1; i<=m; i++) {scanf("%d%d%d",&u,&v,&w); u++,v++;add(u,v,w);add(v,u,w);}Dij();printf("%d %d\n",ans[ed],Max[ed]);return 0 ;
}

 

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

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

相关文章

抠图、换背景、正装图证件照制作方法

本篇灵感是最近又要使用别的底色的正装照的图片。上学的时候&#xff0c;要求证件照的底色是蓝底、党员档案里要求图片的底色是红底、 将来上班的证件照要求是白底&#xff0c;并且无论是考研还是找工作都是制作简历的时候&#xff0c;根据简历的样板不同需要更换不同的底色。 …

TFS的Web门户工作项(七)

在TFS的web门户中有更丰富和更全面的设置和数据展示。 Web门户如图有A&#xff0c;B&#xff0c;C&#xff0c;D四部分组成。A部分为团队项目和项目切换&#xff0c;登录人员和登录人员切换。B部分是Web门户主要功能的菜单&#xff0c;C部分是当前团队项的一些信息的展示&#…

详解多视角3D检测模型 BEVDepth: Acquisition of Reliable Depth for Multi-view 3D Object Detection

本文介绍一个多视角的3D检测模型&#xff1a;BEVDepth&#xff0c;论文收录于 AAAI2023。在这篇文章中&#xff0c;作者提出了一种新的具有可信深度估计的三维物体检测器。本文提出的BEVDepth通过利用激光雷达显式深度监督来提高图像深度估计的可信度。作者引入了摄像机感知深度…

TFS版本管理(八)

目前TFS支持两种版本管理方式&#xff0c;一种是自带的TFS版本控制&#xff0c;一种是Git&#xff0c;后一种是分布式&#xff0c;并且分支功能相对强大&#xff0c;关于Git可以找更详细的资源学习。 如果没有创建项&#xff0c;在web门户中代码下的资源管理器是空的。 团队资…

【PAT - 甲级1006】Sign In and Sign Out (25分)(STLmap)

题干&#xff1a; At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing ins and outs, you are supposed to find the ones who have …

Python开发常用工具库

本文汇总了在使用Python开发时常用到的第三方库和工具。 1.Python 官网地址&#xff1a;https://www.python.org/doc/ 博文地址&#xff1a;《Python编程&#xff1a;从入门到实践》速查表 2.OpenCV&#xff08;图像处理&#xff09; 官网地址&#xff1a;https://opencv.o…

TFS中的统一集成(九)

首先要在TFS服务器上配置生成配置&#xff0c;操作如下&#xff1a; 现在可以创建一个生成定义了&#xff0c;单击团队资源管理器的生成。 新建生成定义&#xff1a; 这里选择的是手动。触发这个生成有很多条件&#xff0c;我们选择手动主式。 在要服务器上共享一个文件夹&…

【PAT - 甲级1009】Product of Polynomials (25分)(模拟,细节)

题干&#xff1a; This time, you are supposed to find AB where A and B are two polynomials. Input Specification: Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N​1​​ a​N​…

常用工具整理:数学,论文,代码等

1. Mathpix&#xff08;图片转数学公式工具&#xff09; 官网地址&#xff1a;Mathpix Snip在线LaTeX公式编辑&#xff1a;在线LaTeX公式编辑器-编辑器 (latexlive.com)推荐另一个开源的工具&#xff1a;Image to LaTex Converter&#xff0c;官网地址&#xff1a;GitHub - ki…

【PAT - 甲级1010】Radix (25分)(二分,进制转化)

题干&#xff1a; Given a pair of positive integers, for example, 6 and 110, can this equation 6 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number. Now for any pair of positive integers N​1​​ and N​2​​, your task …

C#中 ??、 ?、 ?: 、?.、?[ ]、:

1. 可空类型修饰符&#xff08;&#xff1f;&#xff09; 引用类型可以使用空引用表示一个不存在的值&#xff0c;而值类型通常不能表示为空。 例如&#xff1a;string strnull; 是正确的&#xff0c;int inull; 编译器就会报错。 为了使值类型也可为空&#xff0c;就可以使用…

几位无人驾驶领域的杰出科学家

本文介绍了几位无人驾驶领域杰出的科学家们&#xff0c;大家可以关注他们的主页&#xff0c;及时了解一些无人驾驶行业最新动态。 &#xff08;当然还有很多杰出的科学家&#xff0c;这里不一一列举了&#xff0c;暂时只列举出4位&#xff1a;3位外国科学家1位中国科学家&#…

【PAT - 甲级1012】The Best Rank (25分)

题干&#xff1a; To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage s…

Razor语法和Razor引擎大全

一、Razor语法 1、Razor的标识符 解释&#xff1a;字符被定义为Razor服务器代码块的标识符&#xff0c;后面的表示是服务器代码了。web form中使用<%%>中写服务器代码一个道理。在vs工具里面提供了代码着色和智能感应的功能。 { string userName "启超"; &…

【PAT甲级 - 1013】Battle Over Cities (25分)(并查集)

题干&#xff1a; It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep…

让Team Foundation Server/TFS自动记住用户名密码解决方案

在使用Team Foundation Server&#xff08;以下简称TFS&#xff09; 的时候&#xff0c;在每次打开Visual Studio TFS时候&#xff0c;需要输入用户名和秘密&#xff0c;比较麻烦。 现提供一种方法可以解决这个问题&#xff1a; 依次执行下面操作&#xff1a; 打开控制面板--&…

【PAT - 甲级1017】Queueing at Bank (25分)(优先队列,模拟)

题干&#xff1a; Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be ser…

TFS(Team Foundation Server)敏捷使用教程

一、引言 1 中国式软件过程的坏味道 RUP&#xff0c;CMM/CMMI到了中国就变了味。。。。。。 2 Team Foundation Server TFS是软件开发的协作平台&#xff0c;它要解决的首要问题是团队成员的协作问题。比如说&#xff1a; 研发团队内部怎么协作&#xff0c;产品经理&#x…

【PAT - 甲级1020】Tree Traversals (25分)(树的遍历,给定中序后序,求层次遍历)

题干&#xff1a; Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree. Input Specifi…

tfs 未能在以下位置创建报表文件夹 /TfsReports: 授予的权限不足,无法执行此操作

在tfs2015中添加新的Collection时&#xff0c;报一下错误&#xff1a; TF252015: 未能在以下位置创建报表文件夹: /TfsReports/XXXCollection。服务器返回了以下错误: 为用户“domain\name”授予的权限不足&#xff0c;无法执行此操作。。团队项目集合或项目将不具有对报表的访…