PAT1003:Emergency
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
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 思路
和PAT1030一样的思路,Dijkstra + DFS的结合求解就行,只不过这道题只要求输出对应最短路径的条数和征召的最多的小组数,比1030要简单点。 代码
#include<vector>
#include<iostream>
#include<math.h>
using namespace std;
const int Inf = pow(,);
vector<int> team();
vector<vector<int>> graph(,vector<int>(,Inf));
vector<int> dis(,Inf);
vector<vector<int>> pre();
vector<bool> visit(,false);
int n,m,c1,c2;
vector<vector<int>> paths;
vector<int> tmp;
int maxteamnum = -; void dfs(int v)
{
if(v == c1)
{
int tmpteamnum = ;
tmp.push_back(v);
paths.push_back(tmp);
for(int i = tmp.size() - ;i >= ;i--)
{
tmpteamnum += team[tmp[i]];
}
if(maxteamnum < tmpteamnum)
{
maxteamnum = tmpteamnum;
}
tmp.pop_back();
return;
}
tmp.push_back(v);
for(int i = ;i < pre[v].size();i++)
dfs(pre[v][i]);
tmp.pop_back();
} int main()
{
cin >> n >> m >> c1 >> c2;
for(int i = ;i < n;i++)
{
cin >> team[i];
}
for(int i = ;i < m;i++)
{
int s,d;
cin >> s >> d;
cin >> graph[s][d];
graph[d][s] = graph[s][d];
} pre[c1].push_back(-);
dis[c1] = ; //Dijkstra
for(int i = ;i < n;i++)
{
int u = -,mindis = Inf;
for(int j = ;j < n;j++)
{
if(!visit[j] && dis[j] < mindis)
{
u = j;
mindis = dis[j];
}
}
if( u == -)
break;
visit[u] = true;
for(int v = ;v < n;v++)
{
if(!visit[v] && graph[u][v] != Inf)
{
if(dis[u] + graph[u][v] < dis[v])
{
dis[v] = dis[u] + graph[u][v];
pre[v].clear();
pre[v].push_back(u);
}
else if(dis[u] + graph[u][v] == dis[v])
pre[v].push_back(u);
}
}
}
dfs(c2);
cout << paths.size() << " " << maxteamnum << endl;
}
PAT1003:Emergency的更多相关文章
- PAT-1003 Emergency(Dijkstra)
1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of y ...
- pat1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT甲级1003. Emergency
PAT甲级1003. 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服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...
随机推荐
- Django访问量和页面点击数统计
http://blog.csdn.net/pipisorry/article/details/47396311 下面是在模板中做一个简单的页面点击数统计.model阅读量统计.用户访问量统计的方法 简 ...
- Salesforce开发入门
云计算风起云涌,已成势不可挡之势.公司好多项目都依托于云平台了,网络安全采用了zscaler,人力资源系统用的workday,我们case系统也用了salesforce,我自己也在用运行于Google ...
- ping通windows下虚拟机上的linux系统
直接ping linux的ip 直接就失败了. 现在我的windows有两个虚拟网卡 接下来让linux使用VMnet8网卡 修改我的linux系统下的lo网卡的ip地址为VMnet8的ip地址 现 ...
- Developing User Interfaces
Developing a User Interface with ADF Faces Purpose This tutorial covers developing the user interf ...
- LeetCode之旅(18)-Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...
- javascript、ruby和C性能一瞥(1)
测试一下本地js.浏览器中的js以及ruby对于类似算法的性能.结果有些意外:浏览器js最快,本地其次当相差很小:ruby最慢而且不是一个数量级的: 因为写的匆忙,可能有重大问题没能看出来,请各位高人 ...
- 详解linux进程间通信-消息队列
前言:前面讨论了信号.管道的进程间通信方式,接下来将讨论消息队列. 一.系统V IPC 三种系统V IPC:消息队列.信号量以及共享内存(共享存储器)之间有很多相似之处. 每个内核中的 I P C结构 ...
- Qt5中this application has requested the runtime to terminate it in an unusual way 无法运行问题的解决
在windows平台使用Qt5.8mingw版写出的程序,在Qt中运行正常,而以release的形式编译并且补充完必要的dll文件后,在其他电脑上运行出现了以下问题: 经过查阅许多资料和亲身实验,终于 ...
- IT轮子系列(三)——如何给返回类型添加注释——Swagger的使用(二)
前言 一般对外提供API,都会统一一个返回类型,比如所有的接口都统一返回HttpResponseMessage.这样当我们在方法上添加///注释时,是无法清楚的知道都返回字段都又那些以及它们的数据类型 ...
- sublime使用package control安装插件
sublime本身可以集成Package Control来进行插件安装,非常方便. 1. 安装package control(插件包管理) 1.1 进入https://packagecontrol.i ...