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 ...
随机推荐
- javascript常用方法和技巧
浏览器变编辑器 data:text/html, <style type=;right:;bottom:;left:;}</style><div id="e" ...
- Promise.all请求失败重发功能的实现
写爬虫时遇到用Promise.all同时请求多个页面,不可避免的会遇到某些请求失败的情况,这时可以实现一个"重发失败请求"的功能. Promise.all(task).then() ...
- C++自学笔记(3)
类和对象 对象 具体指代一个事物 类 为了便于管理,将信息抽象. 目的不同,抽象的信息也不同(选择性暴露),也就是封装. 通过访问限定符,选择想要暴露和隐藏的信息. 对象实例化 计算机根据一个类的设计 ...
- java实现中值滤波均值滤波拉普拉斯滤波
目录 来对下面的图像滤波,其实就是对各个像素点进行数学运算的过程 均值滤波 中值滤波 拉普拉斯滤波 Sobel滤波 注意 来对下面的图像滤波,其实就是对各个像素点进行数学运算的过程 均值滤波 均值滤波 ...
- mvc拦截请求IHttpModule
代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste ...
- 【CSAPP笔记】11. 存储器层次结构
在没有专门研究存储器系统之前,我们依赖的存储器模型是一个很简单的概念,也就是把它看成一个线性数组,CPU 能在一个常数时间内访问任何一个存储器位置.虽然在研究别的问题时,这是一个有效的模型,但是它不能 ...
- week4a:个人博客作业
本周结对项目的要求: 黄金点游戏是一个数字小游戏,其游戏规则是: N个同学(N通常大于10),每人写一个0~100之间的有理数 (不包括0或100),交给裁判,裁判算出所有数字的平均值,然后乘以0.6 ...
- git学习(一) 如何将项目上传到github
用了github有了段时间,但是感觉都是断断续续的,这次花了点时间来总结下,已方便下次忘记的时候拿出来看一下: 自己主要是参考了这个网站来学习的: git教程 -廖雪峰 第一步: 创建github账号 ...
- 确保你想要修改的char*是可以修改的
void change(char *source) { source[] = 'D'; cout<<source<<endl; } 考虑一下,你有这么一个函数change它的作 ...
- 更新ubuntu的源
什么是Ubuntu的软件源? 我们在使用Debian或者Ubuntu的apt-get工具来安装需要的软件时,其实就是从服务器获取需要安装的软件并把它安装在本地计算机的过程.所谓的软件源,就是我们获取软 ...