题干:

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 ;
}

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

  1. PAT甲级 1003 Emergency 单源Dijkstra最短路

    Solution: 这道题的意思是给定起点和终点,求最短路.但还有一个要求,就是每个城市有救援队,我们要在求得最短路的情况下集结沿途尽可能多的救援队人数. 这道题的n值较小,直接dijkstra即可. ...

  2. PAT甲级1003 Emergency:[C++题解]dijkstra求最短路、最短路条数

    文章目录 题目分析 题目链接 题目分析 分析:求单源最短路,使用dijkstra()算法. 最短路的条数,和最短路中 人数最多的一条,输出最多人数. 本题点比较少,使用邻接矩阵d[N][N]来存. a ...

  3. PAT甲级1003 Emergency Dijkstra算法(堆优化版/朴素版)

    前言   最近花了很多的时间在写JAVA项目上面,疏忽了算法和数据结构的学习.最近突然醒悟基础更为重要,打算从今天开始每天抽出一些时间做下PAT甲级的题目.现有题库的前两题很简单,从第三题开始吧. 题 ...

  4. 1003 Emergency (25 分)

    1003 Emergency (25 分) 题目大意 n个城市m条路,每个城市有救援小组,所有的边的边权已知.给定起点和终点,求从起点到终点的最短路径条数以及最短路径上的救援小组数目之和.如果有多条就 ...

  5. PAT甲级 1003 Emergency

    PAT甲级 1003 Emergency As an emergency rescue team leader of a city, you are given a special map of yo ...

  6. PAT(甲级) 1003. Emergency

    1003 . Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emer ...

  7. 1003 Emergency (25 分)【Dijastra与DFS解法】

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 As an emergency rescue team leader of a city, you are given a spe ...

  8. 19年冬季第二题 PAT甲级 1166 Summit (25分)

    7-3 Summit (25分) A summit (峰会) is a meeting of heads of state or government. Arranging the rest area ...

  9. 1003 Emergency (25 分)【难度: 中等 / 知识点: 变种的Dijkstra】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805523835109376 #include<bits/stdc+ ...

最新文章

  1. AppStore 提供的App信息查询的WebService
  2. CocoaPod 使用之后知后觉
  3. 分类模型的评估方法-召回率(Recall)
  4. 浅谈Perl的类、包、模块与面对对象编程
  5. c++类名字查找与类的作用域
  6. GitHub 新出的 Actions 是什么? 用他做自动测试?
  7. 【TWVRP】基于matlab灰狼算法求解带时间窗的车辆路径规划问题【含Matlab源码 361期】
  8. php 网上支付之易宝支付
  9. HTML浮窗音乐播放器,浮窗音乐播放器3.1.4 支持网易/QQ/虾米/百度等歌单 —— WordPress教程...
  10. 【C/C++学习】之内存分配(new,operator new,placement new)详解
  11. Unity - 人物对象的 LOD 管理
  12. 最全的WiFi速率对应表(802.11b、802.11g、802.11a、802.11n、802.11ac、802.11ax)及速率计算方法
  13. 【必读推荐】程序员的职业素养
  14. 计算机cpu的速度越来越快 这导致,计算机一级笔试模拟题(1-6)
  15. linux内核panic
  16. sqlserver数据库练习3
  17. 人际间亲密关系可能呈现函数式变化
  18. 前端调用后端接口全都报403,但是换个浏览器可以正常访问,请问有大佬知道什么问题吗?
  19. 关于商商城商品表设计(二)
  20. buuctf Crypto 异性相吸

热门文章

  1. [Leedcode][JAVA][第837题][新21点][动态规划][数学]
  2. java一维数组存入_java一维数组
  3. linux下的awk程序在哪里编写,如何编写awk命令和脚本
  4. bucket sort sample sort 并行_MOOSE: 实现大规模并行多物理场仿真(二)
  5. threejs指定对象旋转中心
  6. Print() 语句以及数字赋值语句 中if-else的使用
  7. es删除数据_面试官是怎么来考察你对ES搜索引擎的理解?
  8. python中配置opencv_在Windows中安装OpenCV-Python|四
  9. UE4异步编程专题 - 线程池FQueuedThreadPool
  10. 如何在UE4中创建线程