1003. Emergency (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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的更多相关文章

  1. PAT-1003 Emergency(Dijkstra)

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

  2. pat1003. Emergency (25)

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

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

  4. PAT甲级1003. Emergency

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

  5. 1003. Emergency (25)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  6. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  7. 1003. Emergency

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

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

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

  9. C3P0连接池问题,APPARENT DEADLOCK!!! Creating emergency..... [问题点数:20分,结帖人lovekong]

    采用c3p0连接池,每次调试程序,第一次访问时(Tomcat服务器重启后再访问)都会出现以下错误,然后连接库需要很长时间,最终是可以连上的,之后再访问就没问题了,请高手们会诊一下,希望能帮小弟解决此问 ...

随机推荐

  1. How To Transact Move Order Using INV_PICK_WAVE_PICK_CONFIRM_PUB.Pick_Confirm API

    In this Document Goal   Solution   Sample Code:   Steps:   FAQ   References APPLIES TO: Oracle Inven ...

  2. [转]高级SQL注入:混淆和绕过

    ############# [0×00] – 简介[0×01] – 过滤规避(Mysql)[0x01a] – 绕过函数和关键词的过滤[0x01b] – 绕过正则表达式过滤[0×02] – 常见绕过技术 ...

  3. UML之活动图

    活动图,她的英文名字叫Activity Diagram,是一种说明业务用例实现的工作流程,活动图是UML大家族中用于对系统的动态方面建模的无中图之一. 举个简单的例子,以建房的工作流为例,首先,我们要 ...

  4. hibernate 动态多数据库

    最近老师给了一个任务,需求是这样的 服务器A上有一张表,里面存放了若干个服务器的信息,表的字段包括: private int id; private String serverName; privat ...

  5. Picasso 图片加载库

    Picasso 英文意思国外一个很有名的画家毕加索的名字,国外项目取名还是很有意思的! 从github新下载的picasso项目有依赖其他第三方开源项目okhttp和okio,这两个项目也是相当经典的 ...

  6. C语言关键字static的绝妙用途

    为什么要说static妙,它确实是妙,在软件开发或者单片机开发过程中,大家总以为static就是一个静态变量,在变量类型的前面加上就自动清0了,还有就是加上static关键字的,不管是变量还是关键字, ...

  7. web报表工具FineReport的公式编辑框的语法简介

    FINEREPORT用到公式的地方非常多,单元格(以=开头的便被解析为公式),条件显示,数据字典,报表填报属性值定义,图表标题,轴定义,页眉页脚,甚至单元格的其他属性中的鼠标悬浮提示内容都可以写公式, ...

  8. Mina源码阅读笔记(七)—Mina的拦截器FilterChain

    Filter我们很熟悉,在Mina中,filter chain的用法也类似于Servlet的filters,这种拦截器的设计思想能够狠轻松的帮助我们实现对资源的统一处理.我们先大致连接下mina中的f ...

  9. obj-c编程16:键值编码(KVC)

    我们可以借助obj-c中的键值编码(以后简称KVC,Key-Value Coding)来存取类的属性,通过指定所要访问的属性名字符串标示符,可以使用存取器方法来获取或设置类的属性.下面的例子,借助于K ...

  10. CentOS 7.4上安装mysql 8.0

    我的CentOS版本通过从cat /etc/centos-release查看得知 CentOS Linux release 7.4.1708 (Core) 因此需要yum删除mariadb,然后安装m ...