1003. Emergency (25)
来源:互联网 发布:php是什么 编辑:程序博客网 时间:2024/06/10 19:23
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.
这题很奇怪,谈谈感受.
第一:m的范围不确定,准确来说如果有n个结点的话,连通的道路数为n*(n-1)/2;
第二:审题很重要,第一次以为的是两个所得量是相互独立的,而且还错误的认为路走过后就不能用了...
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <string>#include <cmath>#define maxn 505const int INF = 0x3ffffff;int line[maxn][maxn];int v[maxn];bool vis[maxn];int Count[maxn][2];int n,m,st,ed;int tx,ty;int dis,val;int tmp;using namespace std;void init(){ memset(line,0,sizeof(line)); memset(vis,0,sizeof(vis)); memset(Count,0,sizeof(Count)); dis=INF; val=-INF;}bool judge(int x,int y){ if(line[x][y]&&!vis[y]) return true; return false;}void dfs(int s,int d,int var){ if(s==ed){ if(dis==d){ Count[dis][0]++; Count[dis][1]=max(Count[dis][1],var); } else if(dis>d){ dis=d; Count[dis][0]=1; Count[dis][1]=var; } return; } for(int i=0;i<n;i++){ if(judge(s,i)){ tmp=line[s][i]; //line[s][i]=line[i][s]=0; vis[i]=1; dfs(i,d+tmp,var+v[i]); //line[s][i]=line[i][s]=tmp; vis[i]=0; } } return;}int main(){ init(); scanf("%d%d%d%d",&n,&m,&st,&ed); for(int i=0;i<n;i++) scanf("%d",&v[i]); for(int i=0;i<m;i++){ scanf("%d%d",&tx,&ty); scanf("%d",&line[tx][ty]); line[ty][tx]=line[tx][ty]; } vis[st]=1; dfs(st,0,v[st]); for(int i=0;i<n;i++){ if(Count[i][0]){ printf("%d %d",Count[i][0],Count[i][1]); break; } } return 0;}
- 1003. Emergency (25)
- 1003. Emergency (25)-PAT
- (PAT)1003. Emergency (25)
- 1003. Emergency (25)
- 【C++】1003. Emergency (25)*
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- [PAT]1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 卸载ros的方法
- Tensorflow学习(4)池化层和全连接层
- Java——递归文件目录
- NEUQ实验班讲义001【搜索回顾+贪心初步】
- 启动过程分析及FLASH操作
- 1003. Emergency (25)
- Linux 解决 bash ./ 没有那个文件或目录 的方法
- nuoj 38布线问题(prim最小生成树)
- Android安卓——BroadcastReceiver广播组件
- 无人机驾驶员培训学习记录(十二)
- tar不能解压.zip格式包
- TensorFlow车牌识别完整版(含车牌数据集)
- nodejs +body parser接收 base64并保存图片
- 设计模式之mvc