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

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

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

使用变形的dijkstra算法  并且随时更新最短路径的数目以及能够搜集到的队伍数目。

 #include <iostream>
#include <vector>
#include <cstdlib>
using namespace std; #define MaxDistance 10000
vector< vector <int>> GMatrix;
vector<int> dist;
vector<int> teams; int N,M,start,en; void dijkstra()
{
vector<int> flag(N, );
vector<int> pathcount(N, );
vector<int> amount(N, );
for (size_t i = ; i < N; i++)//initial the dist
{
if (GMatrix[start][i] != -)
dist.push_back(GMatrix[start][i]);
}
amount[start] = teams[start];
pathcount[start] = ; while()
{
int min = MaxDistance;
int k;
for (size_t j = ; j < N; j++)
{
if ((flag[j] == ) && (dist[j] < min))
{
min = dist[j];
k = j;
}
}
if (k == en|| min==MaxDistance) break; //can not find the mini or find the end node, then break the iterative while(1)
flag[k] = ;
for (size_t j = ; j < N; j++)
{
int temp = dist[k] + GMatrix[k][j];
if ((flag[j] == ) && (temp < dist[j]))
{
dist[j] = temp;
amount[j] = amount[k] + teams[j]; //update the teams you can gather
pathcount[j] = pathcount[k];// update the shortest road sums
}
else if ((flag[j] == ) && (temp == dist[j]))
{
pathcount[j] += pathcount[k]; //update
if (amount[k] + teams[j]>amount[j])
amount[j] = amount[k] + teams[j]; //update
}
}
}
//for (size_t i = 0; i < N; i++)//output the dist for check
//{
// cout << dist[i] << " ";
//}
//cout << endl;
cout << pathcount[en] << " " << amount[en] << endl; }
int main()
{
cin >> N >> M >> start >> en;
for (size_t i = ; i < N; i++)//input the teams
{
int t; cin >> t;
teams.push_back(t);
}
for (size_t i = ; i < N; i++)//initial the GMtraix
{
vector<int> arr(N, MaxDistance);
GMatrix.push_back(arr);
GMatrix[i][i] = ;//for the same start and end, the dist=0;
}
for (size_t i = ; i < M; i++)//input the road to the graph
{
int left, right, road;
cin >> left >> right >> road;
GMatrix[left][right] = road; GMatrix[right][left] = road;
}
dijkstra(); return ;
}

1003. Emergency的更多相关文章

  1. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

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

  2. PAT 解题报告 1003. Emergency (25)

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

  3. PAT 1003. Emergency (25)

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

  4. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

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

  5. PAT 1003 Emergency

    1003 Emergency (25 分)   As an emergency rescue team leader of a city, you are given a special map of ...

  6. PAT 1003 Emergency[图论]

    1003 Emergency (25)(25 分) As an emergency rescue team leader of a city, you are given a special map ...

  7. 1003 Emergency (25 分)

    1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of y ...

  8. 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 ...

  9. PAT甲级1003. Emergency

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  10. PAT 甲级 1003. Emergency (25)

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

随机推荐

  1. 配置Kotlin环境(DataBinding)

    1.安装Kotlin插件 在plugin中搜索kotlin,安装两个kotlin插件,重新启动Android Studio.2.build.gradle(project level) buildscr ...

  2. JS实现悬浮移动窗口(悬浮广告)的特效

    页面加载完成之后向页面插入窗口,之后向窗口插入关闭按钮,使用setInterval()函数触发moves()函数开始动画   js方法: 复制代码代码如下: <!DOCTYPE HTML PUB ...

  3. Routine

    前端要学习三个部分:HTML,CSS,JavaScript(简称JS),因此首先明确三个概念:HTML是内容层,它的目的是表示一个HTML标签在页面里是个什么角色. CSS是样式层,它的目的是表示一块 ...

  4. FTP远程文件传输命令

    使用ftp命令进行远程文件传输 ftp命令是标准的文件传输协议的用户接口.ftp是在TCP/IP网络上的计算机之间传输文件的简单有效的方法.它允许用户传输ASCII文件和二进制文件. 在ftp会话过程 ...

  5. IO流04--毕向东JAVA基础教程视频学习笔记

    Day20 01 File概述02 File对象功能-创建和删除03 File对象功能-判断04 File对象功能-获取05 File对象功能-文件列表106 File对象功能-文件列表207 列出目 ...

  6. 5个示例带你学习AngularJS

    直到现在,你或许已经听说过AngularJS了,一个改变你对web应用思考方式,由谷歌开发的令人兴奋的开源框架.关于它的文章已经写得非常之多,但我发现还是要写些给那些更喜欢快速且实际例子的开发者.当今 ...

  7. Chrome浏览器二维码生成插件

      猛击就可以使用啦->>>猛击使用   源码如下: 源码打包   源码: jquery-2.1.3.min.js jquery.qrcode.min.js https://gith ...

  8. Tomcat:基于Apache+Tomcat的集群搭建

    根据Tomcat的官方文档说明可以知道,使用Tomcat配置集群需要与其它Web Server配合使用才可以完成,典型的有Apache和IIS. 这里就使用Apache+Tomcat方式来完成基于To ...

  9. RTP、RTCP协议学习-2015.04.15

    最近做视频编解码部分,传输采用RTP协议.对学习做个记录 1.简介 实时传输协议(Real-time Transport Protocol或简写RTP)是一个网络传输协议,它是由IETF的多媒体传输工 ...

  10. 烂泥:mysql帮助命令使用说明

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在安装.管理和使用mysql过程中,你是不是需要记忆很多的mysql命令.而且对于新手来说,很不多的命令不知道该如何应用,对于老手来说很多命令时间长了忘 ...