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服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...
随机推荐
- 《java入门第一季》之面向对象(构造方法)
/* 构造方法: 给对象的数据进行初始化 格式: A:方法名与类名相同 B:没有返回值类型,连void都没有 C:没有具体的返回值 */ class Student { private String ...
- PDA(Windows Mobile)调用远程WebService
之前用模拟器测试过调用远程的WebService,发现总是提示"无法连接到远程服务器"的错误,不管是Windows Mobile6.0 还是6.5都是一样,按照网上的办法,改注册表 ...
- CCRenderBuffer初始化中的render state参数
绘制纹理三角形的渲染状态(render state)已经被CCSprite基类设置过了,所以你可以简单的将self.renderState传递过去就可以了. 渲染状态是混合模式(blend mode) ...
- AngularJS进阶(五)Angular实现下拉菜单多选
Angular实现下拉菜单多选 写这篇文章时,引用文章地址如下: http://ngmodules.org/modules/angularjs-dropdown-multiselect http:// ...
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
In this Document Goal Solution References APPLIES TO: PL/SQL - Version 9.2.0.1 to 12.1.0.1 [Re ...
- cocoa编程第4版 8.6 挑战2 解答
该版本的RaiseMan不用Array Controller,全部手写代码. 要注意的有以下几点: 1.TableView每列的sort设置和AC版的相同,但要手写排序代理方法 2.TableView ...
- 史上最强Spring mvc入门
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- android decorView详解
摘要 一.DecorView为整个Window界面的最顶层View. 二.DecorView只有一个子元素为LinearLayout.代表整个Window界面,包含通知栏,标题栏,内容显示栏三块区域. ...
- 存储引擎-Bitcast
Bitcast是一种日志型的基于hash表结构的健值对的存储系统,最早追溯于Riak分布式数据库. 目前,Berkeley DB,Tokyo Cabinet,Innostore都使用了这种存储引擎.使 ...
- 棋盘的完美覆盖问题,c++代码实现
#include "stdafx.h" #include<iostream> #include<iomanip> using namespace std; ...