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

提交代码

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

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

  2. PAT 解题报告 1003. Emergency (25)

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

  3. PAT 1003. Emergency (25)

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

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

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

  5. PAT1003:Emergency

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

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

  7. PAT 甲级 1003. Emergency (25)

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

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

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

  9. PAT-1003 Emergency(Dijkstra)

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

随机推荐

  1. laravel中get方式表单提交后, 地址栏数据重复的问题

    csrf_field这个要放form表单下面第一行的位置

  2. C# 属性与字段

    属性和字段的区别: 属性是逻辑字段,是字段的扩展,并不占用实际的内存:而字段占用内存空间. 属性可以被其他类访问:而非public的字段不能被直接访问. 属性可以对接受的数据在范围上做限定:而字段不能 ...

  3. NSCalendar日历

    前言 NSCalendar 对世界上现存的常用的历法进行了封装,既提供了不同历法的时间信息,又支持日历的计算. NSCalendar -- 日历类,它提供了大部分的日期计算接口,并且允许您在NSDat ...

  4. day08.4-samba共享网盘服务

    1. 安装软件:yum   install   samba   -y 2. 新建共享目录物理路径:mkdir   /zizaijiapu 修改配置文件:vim   /etc/samba/smb.con ...

  5. React杂篇(1) -- 打包发布注意事项

    打包后资源路径 问题:直接打包会出现一下情况: 方式一: package.json文件下加入homepage字段 { "name": "wap-v2", &qu ...

  6. kali linux之端口扫描

    端口对应网络服务及应用端程序,服务端程序的漏洞通过端口攻入 发现开放的端口,有更具体的攻击面 nmap hping3 scapy都可以 nmap隐蔽扫描 扫描抓包 nmap僵尸扫描 先发现僵尸机,僵尸 ...

  7. 《Andrew Ng深度学习》笔记2

    神经网络基础 1.图计算 计算时有两种方法:正向传播和反向传播.正向传播是从底层到顶层的计算过程,逐步推出所求公式.反向传播是从顶层到底层,从已知的式子求出因变量的影响关系. 在这里用到的反向传播算法 ...

  8. fork()父子进程文件描述符的关系

    父子进程共享文件描述符:此说法,其实是父子进程共享 文件表项(父进程和子进程共享同一个file table entry) 由于子进程是父进程的拷贝,子进程会拷贝父进程的进程描述符中的文件描述符表,可以 ...

  9. 如何在UITableViewController上添加一个固定的视图

    最近在使用UITableViewController,想在上面添加一个固定的视图,不随ScrollView滑动而移动.最后找到2种解决办法,一种是计算TableView的偏移,调整视图的位置,不断更新 ...

  10. HDU - 5997 树状数组+set

    和之前一道省选题目很像: (梦幻布丁): 我们维护的时候用树状数组维护,在断电处打上标记: 合并的时候小的合并到大的里面: #include<iostream> #include<c ...