1003 Emergency(25 分)
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, 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 Specification:
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<iostream>
#include<cstring> using namespace std; static const int INFTY = (<<);
static const int MAX = ;
static const int WHITE = ;
static const int GRAY = ;
static const int BLACK = ; int n, M[MAX][MAX], Team[MAX];
int w[MAX], num[MAX]; void dijsktra(int source){
int d[MAX];
int color[MAX];
for(int i=;i<n;i++){
d[i] = INFTY;
color[MAX] = WHITE;
}
memset(w, , sizeof(w));
memset(num, , sizeof(num));
d[source] = ;
color[source] = GRAY;
num[source] = ;
w[source] = Team[source];
while(true){
int minv = INFTY;
int u = -;
for(int i=;i<n;i++){
if(minv>d[i]&&color[i]!=BLACK){
u = i;
minv = d[i];
}
}
if(u==-){
break;
}
color[u] = BLACK;
for(int v=;v<n;v++){
if(color[v]!=BLACK&&M[u][v]!=INFTY){
if(d[v]>d[u]+M[u][v]){
d[v] = d[u] + M[u][v];
color[v] = GRAY;
w[v] = w[u] + Team[v];
num[v] = num[u];
}
else if(d[v]==d[u]+M[u][v]){
if(w[v]<w[u] + Team[v]){
w[v] = w[u] + Team[v];
}
num[v] += num[u];
}
}
}
}
} int main(){
int road, source, target;
cin>>n>>road>>source>>target;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
M[i][j] = INFTY;
}
}
int cnt;
for(int i=;i<n;i++){
cin>>cnt;
Team[i] = cnt;
}
int u, v, cost;
for(int i=;i<road;i++){
cin>>u>>v>>cost;
M[v][u] = M[u][v] = cost;
}
dijsktra(source);
cout<<num[target]<<" "<<w[target]<<endl;
return ;
}
需要注意的是MAX的设定,很奇怪的是,题目给定最大是500,设定五百会有一些测试点过不去,得开的稍微大一点。还有就是,数组需要进行初始化。
1003 Emergency(25 分)的更多相关文章
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- PAT 1003 Emergency (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- 1003 Emergency (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- 【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)
题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 1003 Emergency (25)(25 point(s))
problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
随机推荐
- iOS 源代码混淆(初步混淆)
我们可以用classdump对原程序进行 dump,像上篇文章( Class-dump 安装和使用记录(导出应用的头文件)),我们可以看到所有.h 文件全暴露了(如下图) 点击HWAccount.h后 ...
- No.10_分数分配
C#队一共有7名成员,因此团队贡献分一共350分. 分配方式应当反映绝大部分组员的真实贡献情况,即由贡献决定分数. 另外保证一定的奖惩措施,充分调动组员的积极性,鞭策团队向前迈进. 对于团队贡献分数的 ...
- [BUAA软工]第零次博客作业---问题回答
[BUAA软工]第0次博客作业 项目 内容 这个作业属于哪个课程 北航软工 这个作业的要求在哪里 第0次个人作业 我在这个课程的目标是 学习如何以团队的形式开发软件,提升个人软件开发能力 这个作业在哪 ...
- 20162328蔡文琛 大二 十二周课上测试 hash
- bata1
目录 组员情况 组员1(组长):胡绪佩 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最新成果 团 ...
- 小学四则运算结对项目报告【GUI】
写在前面 这次的结对项目我做了很长时间,感触也很多.在这次项目中我使用了Java GUI作为和用户的交互方式,但是在上Java课的时候我对GUI和事件驱动这里并没有学的多好,可能是当时对编程还没有什么 ...
- 蜗牛慢慢爬 LeetCode 6. ZigZag Conversion [Difficulty: Medium]
题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows li ...
- PAT 甲级 1137 Final Grading
https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608 For a student taking t ...
- 利用ceye中的dns来获取数据
安恒杯的一道命令执行题目 查看,存在robots.txt文件 查看index.txt文件,存在where_is_flag.php文件 使用cat没有任何回显 可以使用ceye平台利用dns记录内容,网 ...
- uva 11525(线段树)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...