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
 #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,设定五百会有一些测试点过不去,得开的稍微大一点。还有就是,数组需要进行初始化。

最新文章

  1. Innodb锁机制:Next-Key Lock 浅谈
  2. ES6新特性(函数默认参数,箭头函数)
  3. iOS -- 给model赋值时走了[self setValuesForKeysWithDictionary:dic]不走setvalue: forked:
  4. 【笨嘴拙舌WINDOWS】字符类型与字符串
  5. AutoIt 函数学习之----WinWaitActive
  6. NYOJ--32--SEARCH--组合数
  7. ssh商城源码 2017.6.30
  8. Java面向接口编程,低耦合高内聚的设计哲学
  9. Mysql中concat()、concat_ws()和 group_concat()的用法
  10. QTableWidget class
  11. sqlPlus基本操作
  12. Item 20: 使用std::weak_ptr替换会造成指针悬挂的类std::shared_ptr指针
  13. 027_磁盘维护命令du等
  14. onclick传对象
  15. golang 字符串统计
  16. CentOS6.5安装配置PPTP
  17. 拓扑_dfs——找最小环
  18. Nginx 灰度实现方式(支持纯灰度,纯生产,50度灰及更多比例配置)
  19. 深入理解Java中配置环境变量
  20. strtr、str_replace()、substr_replace、preg_replace之间的区别

热门文章

  1. 转载---VisualStudioCode通过SSH远程编辑文件
  2. Django_rest_framework_版本(待验证)
  3. #1490 : Tree Restoration-(微软2017在线笔试)
  4. sublime c/c++ 环境
  5. android实战开发02
  6. WebGL学习笔记一
  7. String 类 常用函数
  8. Alpha阶段敏捷冲刺②
  9. mysql只修改年月日,时分秒不变
  10. Linux进程调度策略的发展和演变(转)