Source:

PAT A1003 Emergency (25 分)

Description:

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 (≤) - 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 Mlines 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

Keys:

Code:

 /*
Data: 2019-06-19 15:37:05
Problem: PAT_A1003#Emergency
AC: 16:05 题目大意:
求权值最大的最短路径
输出:
最短路径数,最大带权路径长度
*/
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=,INF=1e9;
int grap[M][M],vis[M],d[M],w[M];
int n,m,st,dt,c[M],t[M]; void Dijskra(int s)
{
fill(vis,vis+M,);
fill(d,d+M,INF);
fill(c,c+M,);
fill(t,t+M,);
d[s]=;
t[s]=;
c[s]=w[s];
for(int i=; i<n; i++)
{
int u=-,Min=INF;
for(int j=; j<n; j++)
{
if(vis[j]== && d[j]<Min)
{
u=j;
Min=d[j];
}
}
if(u==-) return;
vis[u]=;
for(int v=; v<n; v++)
{
if(vis[v]== && grap[u][v]!=INF)
{
if(d[u]+grap[u][v] < d[v])
{
d[v]=d[u]+grap[u][v];
c[v]=c[u]+w[v];
t[v]=t[u];
}
else if(d[u]+grap[u][v]==d[v])
{
t[v] += t[u];
if(c[u]+w[v] > c[v])
c[v]=c[u]+w[v];
}
}
}
}
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE fill(grap[],grap[]+M*M,INF);
scanf("%d%d%d%d", &n,&m,&st,&dt);
for(int i=; i<n; i++)
scanf("%d", &w[i]);
for(int i=; i<m; i++)
{
int v1,v2;
scanf("%d%d", &v1,&v2);
scanf("%d", &grap[v1][v2]);
grap[v2][v1]=grap[v1][v2];
}
Dijskra(st);
printf("%d %d", t[dt],c[dt]); return ;
}

最新文章

  1. 2016年Web前端面试题目
  2. C++多线程の线程通信future,promise,async
  3. How to (seriously) read a scientific paper
  4. 关于 MAXScript 如何剪切文件夹
  5. [原创]Matlab之GUI生成EXE文件
  6. Awesome Javascript(中文翻译版)
  7. cocos2d-x的helloLua例子函数名定义误导初学者
  8. Windows下Jekyll安装
  9. 快速排序OC、Swift版源码
  10. Linux密码保护
  11. iOS学习——浅谈RunLoop
  12. table切换jquery插件 jQuery插件写法模板 流程
  13. React 最简单的入门教程
  14. Failed to auto-configure a DataSource: &#39;spring.datasource.url&#39; is not specified and no embedded datasource could be auto-configured.
  15. 20155301 Exp6 信息搜集与漏洞扫描
  16. php加密总结
  17. virtualbox+vagrant学习-2(command cli)-17-vagrant ssh命令
  18. 使用Spring提供Quartz来实现定时任务
  19. 微信小程序 --- 获取网络状态
  20. fork: retry: Resource temporarily unavailable

热门文章

  1. C++学习之多重继承与虚继承
  2. 金典 SQL笔记(6)
  3. CocoaPods pod instal慢、卡住解决方法
  4. IOS - 设置与帮助界面
  5. C# 文件里的类不能进行设计,因此未能为该文件显示设计器
  6. Tcl学习之--命名空间
  7. 专訪印度电商Snapdeal CEO:学阿里还是京东
  8. 三种常见的编码:ASCII码、UTF-8编码、Unicode编码等字符占领的字节数
  9. oc76--NSMutableDictionary
  10. 【转】Android 关闭多个视图Intent.FLAG_ACTIVITY_CLEAR_TOP用法