pat1003. Emergency (25)
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
dijstra做法:
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
#define size 505
int city[size],map[size][size],team[size],roadnum[size],dis[size];
int n,m,s,e;
void dijstra(int s,int e){
int i,j,k;
dis[s]=;//表示已经在集合中
roadnum[s]=;
while(s!=e){
for(i=;i<n;i++){
if((dis[i]==-&&map[s][i]!=-)||(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]>dis[s]+map[s][i])){//更新
dis[i]=dis[s]+map[s][i];
team[i]=team[s]+city[i];
roadnum[i]=roadnum[s];
}
else{
if(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]==dis[s]+map[s][i]){
if(team[i]<team[s]+city[i])
team[i]=team[s]+city[i];
roadnum[i]+=roadnum[s];
}
}
}
dis[s]=;
int min=-;
for(i=;i<n;i++){
if(dis[i]>&&(min==-||dis[i]<min)){
min=dis[i];
s=i;
}
}
}
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
scanf("%d %d %d %d",&n,&m,&s,&e);
int i,j,k;
for(i=;i<n;i++){
scanf("%d",&city[i]);
}
int a,b,l;
for(i=;i<n;i++){
dis[i]=-;
team[i]=city[i];
for(j=;j<n;j++){
map[i][j]=map[j][i]=-;//初始化
}
}
for(i=;i<m;i++){
scanf("%d %d %d",&a,&b,&l);
if(map[a][b]==-||map[a][b]>l)//确保最小化
map[a][b]=map[b][a]=l;
}
dijstra(s,e);
printf("%d %d\n",roadnum[e],team[e]);
return ;
}
DFS做法:
pat1003. Emergency (25)的更多相关文章
- 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 (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT1003:Emergency
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 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 ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- PAT-1003 Emergency(Dijkstra)
1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of y ...
随机推荐
- Android学习笔记 TextSwitcher文本切换组件的使用
activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- HtmlAgilityPack 使用
或.无属性.属性个数.属性值: var preceding_siblings = node.SelectNodes("preceding-sibling::input| preceding- ...
- 「TJOI2015」线性代数
题目链接 戳我 \(Describe\) 题目描述 为了提高智商,\(ZJY\)开始学习线性代数.她的小伙伴菠萝给她出了这样一个问题:给定一个\(n×n\)的矩阵\(B\)和一个\(1×n\)的矩阵\ ...
- Dos命令 WIN10 WIFI命令
设置WIFI命令: netsh wlan set hostednetwork ssid=T key=123456798 mode=allow netsh wlan start hostednetwor ...
- 842. Split Array into Fibonacci Sequence
Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like ...
- git配置本地环境(phpstudy/tortoisegit/git等)
1.下载安装phpstudy 2.下载安装git 下载地址:https://git-scm.com/downloads 3.下载安装tortoisegit,电脑64位就下载这个,如图: 4.下载安装“ ...
- 12、OpenCV Python 图像梯度
__author__ = "WSX" import cv2 as cv import numpy as np def lapalian_demo(image): #拉普拉斯算子 # ...
- Reviewing notes 1.1 of Advanced algebra
♦Linear map Definition Linear map A linear map from vector space V to W over a field F is a function ...
- angularjs中向html页面添加内容节点元素代码段的两种方法
第一种方式:原生JS向html页面添加内容节点元素代码段: <!DOCTYPE html> <html> <head> <meta charset=" ...
- AndroidManifest.xml警告
新建一个android项目后,AndroidManifest.xml有一个黄色警告 作为一个新手,不知道这个警告来自哪里,点击界面下方的不同标签,才知道来自图中的位置 第8行中,application ...