PAT 1003 Emergency
来源:互联网 发布:mac怎么下载歌 编辑:程序博客网 时间:2024/06/05 10:52
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.
5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output
2 4
//DFS#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define MIN 100000000int n,m,start,to;int map[505][505];int hand[505];int book[505];int minDis=MIN,count,hands;//minDis:最短距离 count:最短距离的路径数目 hands:人手void DFS(int x,int dis,int sum){if(dis>minDis)//剪枝 当路径大于当前最短路径,即刻返回return;if(x==to){if(dis==minDis){//路径依然为当前最短路径if(sum>hands)hands=sum;count++;return;}minDis=dis;//新最短路径count=1;hands=sum;return;}for(int i=0;i<n;i++){if(map[x][i]!=0&&!book[i]){book[i]=1;DFS(i,dis+map[x][i],sum+hand[i]);book[i]=0;}}}int main(){int x,y,w;cin>>n>>m>>start>>to;memset(map,0,sizeof(map));memset(book,0,sizeof(book));for(int i=0;i<n;i++)scanf("%d",&hand[i]);for(int i=1;i<=m;i++){scanf("%d%d%d",&x,&y,&w);map[x][y]=map[y][x]=w;}book[start]=1;DFS(start,0,hand[start]);cout<<count<<' '<<hands<<endl;return 0;}
- Pat 1003 Emergency (25)
- ZJU PAT 1003 Emergency
- PAT 1003 Emergency
- PAT-A | 1003 | Emergency
- PAT 1003 Emergency (25)
- PAT 1003 Emergency
- PAT 1003 Emergency
- PAT 1003 Emergency
- pat 甲级 1003 Emergency
- 【PAT 1003】 Emergency 图论Dijkstra
- PAT Advanced Level 1003:Emergency
- PAT 1003:Emergency解题报告
- 浙大PAT 1003题 1003. Emergency
- pat 1003 Emergency (值得重点回顾)
- 浙大PAT advanced level 1003 emergency
- Pat(Advanced Level)Practice--1003(Emergency)
- PAT (Advanced Level) Practise 1003Emergency (25)
- PAT 甲级 1003Emergency(Dijkstra最短路)
- windows下全志 A20 Android script.fex 调试工具
- 收集的35个 jQuery 小技巧/代码片段
- Linux常用命令整理
- UVA 1590
- 链路状态路由协议,调用分发列表的时候,作用分析,distribute-list
- PAT 1003 Emergency
- 【集成学习】scikit-learn随机森林调参小结
- 重拾CSS(1)CSS中的margin属性
- c++ 凌驾于字符串之上的string类
- android加固系列—2.加固前先要学会破解,调试内存值修改程序走向
- oracle分析函数技术详解(配上开窗函数over())
- 百练2801解题报告---填词
- pat-a1024. Palindromic Number (25
- Boolean.valueOf(true)和true的区别