PAT_A1003#Emergency
Source:
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, 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 Mlines 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 C1and 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
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 ;
}
PAT_A1003#Emergency的更多相关文章
- 1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- 1003. Emergency
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]
采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义重复
从图片中我们可以看到,这里在语义上有一定的重复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,不过由于Android4.3在锁屏功能上比起老版本做了很大的改动,而 ...
- Active Session History (ASH) Performed An Emergency Flush Messages In The Alert Log
Active Session History (ASH) Performed An Emergency Flush Messages In The Alert Log (文档 ID 1385872.1 ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
随机推荐
- LeetCode 709. To Lower Case (转换成小写字母)
题目标签:String 题目让我们把大写字母转换成小写,只要遇到的是大写字母,把它 + 32 变成 小写就可以了. Java Solution: Runtime beats 100.00% 完成日期: ...
- AutoLayout初战----Masonry与FDTemplateLayoutCell实践
学iOS也有几个月了.一直都是纯代码开发,菜鸟入门,到今天还处在Frame时代.刚好近期项目在提审.有点时间能够学学传说中的AutoLayout.事实上.就是android的相对布局(Relative ...
- Linux 下查找文件或文件夹
有些在我看来比较实用的命令,在这里记一下,避免每次都搜索一轮. 1.查找文件和文件夹 $ find . -name "mongo*" 从当前路径开始,向子目录查找名字含有 &quo ...
- BestCoder Round #60/HDU 5505 暴力数学
GT and numbers 问题描述 给出两个数NN和MM. NN每次可以乘上一个自己的因数变成新的NN. 求最初的NN到MM至少需要几步. 如果永远也到不了输出-1−1. 输入描述 第一行读入一个 ...
- java多线程——线程通信
一.线程通信目标 1.线程通信的目标是使线程间能够互相发送信号 2.线程通信使线程能够等待其他线程的信号 二.几种方式 1.通过共享对象 2.忙等待 线程 B 运行在一个循环里,以等待信号 (不释放c ...
- c++ 编译器会绕过拷贝构造函数
C++ primer P442 P447:在拷贝初始化过程中,编译器可以跳过拷贝构造函数,直接创建对象.即,编译器允许将下面的代码 "; //1 改写为 "); //2 由于str ...
- oc77--结构体,NSNumber,NSValue,NSDate,NSCalendar
// // main.m // OC中的常用结构体 // #import <Foundation/Foundation.h> int main(int argc, const char * ...
- Web开发必须知道的知识点
Web前端必须知道 一.常用那几种浏览器测试.有哪些内核(Layout Engine) 1.浏览器:IE,Chrome,FireFox,Safari,Opera. 2.内核:Trident,Gecko ...
- akka设计模式系列-Chain模式
链式调用在很多框架和系统中经常存在,算不得上是我自己总结的设计模式,此处只是简单介绍在Akka中的两种实现方式.我在这边博客中简化了链式调用的场景,简化后也更符合Akka的设计哲学. trait Ch ...
- ckeditor 工具栏的配置
config.toolbar = [ ['Undo','Redo'], ['Font','FontSize'], ['Bold','Ita ...