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 (≤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 Specification:

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

思路

题意是,让你求C1->C2 最短路径的个数,然后输出你能调动救援队的最大值。

网上很多人是基于dijkstra做出来的,我只写了个简单的搜索。

用数组记录城市之间的道路长度。注意有个坑,可能出现自己救自己的情况(即 C1=C2)。

#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <map>
using namespace std; int m[505][505];
int n, M, c1, c2;
int num[505];
int vis[505];
int road_num;
int max_n = - 1;
int min_dis = INT_MAX; void dfs(int index, int sum, int dis){
if(dis > min_dis) return;
if(index == c2){
if(dis < min_dis){
min_dis = dis;
road_num = 1;
max_n = sum;
}
else if(dis == min_dis){
road_num++;
max_n = max(sum, max_n);
}
return;
}
for(int i = 0; i < n; i++){
if(m[index][i] && !vis[i]){
vis[i] = 1;
dfs(i, sum + num[i], dis + m[index][i]);
vis[i] = 0;
}
}
} int main() {
cin >> n >> M >> c1 >> c2;
for(int i = 0; i < n; i++){
cin >> num[i];
}
for(int i = 0; i < M; i++){
int s = 0, e = 0, l = 0;
cin >> s >> e >> l;
m[s][e] = l;
m[e][s] = l;
}
if(c1 != c2) vis[c1] = 1;
dfs(c1, num[c1], 0); cout << road_num << " " << max_n;
return 0;
}

PAT 1003 Emergency (25分)的更多相关文章

  1. 1003 Emergency (25分) 求最短路径的数量

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

  2. PAT 1003. Emergency (25)

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

  3. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

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

  4. 【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)

    题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...

  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. PAT 解题报告 1003. Emergency (25)

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

  7. PAT 甲级 1003. Emergency (25)

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

  8. PAT 1003 Emergency[图论]

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

  9. 1003 Emergency (25)(25 point(s))

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

随机推荐

  1. 路飞-celery框架

    Celery 官方 Celery 官网:http://www.celeryproject.org/ Celery 官方文档英文版:http://docs.celeryproject.org/en/la ...

  2. 安装Oracle进行先决条件检查时显示 Environment variable:"PATH" 失败”

    问题已解决:安装时exe可执行文件的目录也不能有中文,安装时注意目录一定要按oracle的格式.运行安装程序时,要用右键--> 要以管理员方式启动. 原文: 用到oracle数据库,由于电脑装的 ...

  3. PHP高并发和大流量怎么解决?

    PHP高并发和大流量的解决方案 一 高并发的概念 在互联网时代,并发,高并发通常是指并发访问.也就是在某个时间点,有多少个访问同时到来. 二 高并发架构相关概念 1.QPS (每秒查询率) : 每秒钟 ...

  4. PyQt5遇到的一个坑 "ImportError: unable to find Qt5Core.dll on PATH" 及解决办法

    最近再实现一个功能,主要是将自动化测试界面化 环境组合为:Windows 64bit + PyCharm + Python + PyQt5 + Pyinstaller + Inno Setup PS ...

  5. Catalyst9K设备介绍

    Catalyst9K系列的里面包含了多款交换机,以及无线控制器,甚至包含了无线AP,如下将简单的介绍这几款产品的情况: 首先,这是一种总体的对应关系: 1.Catalyst9200 Series 主要 ...

  6. 《一句话理解Vue核心内容》阅读笔记

    Vue.js(读音 /vjuː/,类似于 view) 是一套构建用户界面的渐进式框架. 在解释什么是渐进式框架之前,有必要了解一下什么是框架 在最初的前端开发中,我们利用JS获取HTML中的DOM元素 ...

  7. 每天进步一点点------DE2-70-TV例子说明

    module Reset_Delay(iCLK,iRST,oRST_0,oRST_1,oRST_2); input iCLK; input iRST; output reg oRST_0; outpu ...

  8. 【Node.js安装步骤】

    "Node.js是一个Javascript运行环境(runtime environment),发布于2009年5月,由Ryan Dahl开发,实质是对Chrome V8引擎进行了封装.本文详 ...

  9. DFS(深度优先搜索)

    基本概念 深度优先搜索算法(Depth First Search,简称DFS):一种用于遍历或搜索树或图的算法. 沿着树的深度遍历树的节点,尽可能深的搜索树的分支.当节点v的所在边都己被探寻过或者在搜 ...

  10. sqlmap+burpsuit

    sqlmap可以批量扫描burpsuit导出的requests日志文件,从而进行批量扫描是否存在SQL注入. 首先设置burpsuit记录代理的Requests 把记录的日志文件保存在sqlmap的目 ...