1003. Emergency (25)
2015-07-17 19:41
267 查看
Sample Output1003. 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.InputEach 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.OutputFor 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 Input5 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
2 4
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
7月19日 21:35 | 答案正确 | 25 | 1003 | C++ (g++ 4.7.2) | 3 | 384 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 248 | 10/10 |
1 | 答案正确 | 1 | 308 | 3/3 |
2 | 答案正确 | 1 | 256 | 3/3 |
3 | 答案正确 | 2 | 308 | 3/3 |
4 | 答案正确 | 2 | 256 | 3/3 |
5 | 答案正确 | 3 | 384 | 3/3 |
#include<iostream> using namespace std; #define MAX 0x7fffffff struct Esave { long int save; long int LastIndex; }; struct Mlist { int to; long int cost; long int FrontIndex; }; long int Gmap(Esave *nl, Mlist *me, long int i, int c1, int c2, long int ct) { me[i].cost = ct; me[i].to = c2; me[i].FrontIndex = nl[c1].LastIndex; nl[c1].LastIndex = i++; me[i].cost = ct; me[i].to = c1; me[i].FrontIndex = nl[c2].LastIndex; nl[c2].LastIndex = i++; return i; } void EMDFS(Esave*nl, Mlist*me, long int *min, int c1, int c2, bool *visit, long int*max, long int lastmin, long int *count, long int maxx) { long int t, tempmax, tempmin, id; visit[c1] = false; t = nl[c1].LastIndex; tempmin = lastmin; tempmax = maxx; while (t>0) { id = me[t].to; tempmin = lastmin + me[t].cost; tempmax = maxx + nl[id].save; if (visit[id] == true && id != c2) EMDFS(nl, me, min, id, c2, visit, max, tempmin, count, tempmax); else if (id == c2) { if ((*min)>tempmin) { (*min) = tempmin; (*max) = tempmax; (*count)=1; } else if ((*min) == tempmin) { if ((*max)<tempmax) { (*max) = tempmax; } (*count)++; } } t = me[t].FrontIndex; } visit[c1] = true; } int main() { int N, i, link1, link2, C1, C2; long int M, costt, temp, t; bool *flag; Esave *NLastIndex; Mlist *MEmergency; cin >> N >> M >> C1 >> C2; NLastIndex = new Esave ; MEmergency = new Mlist[(M + 1) * 2]; MEmergency[0].cost = 0; MEmergency[0].to = 0; MEmergency[0].FrontIndex = 0; flag = new bool ; for (i = 0; i<N; i++) { cin >> NLastIndex[i].save; NLastIndex[i].LastIndex = 0; flag[i] = true; } for (i = 0, temp = 1; i<M; i++) { cin >> link1 >> link2 >> costt; temp = Gmap(NLastIndex, MEmergency, temp, link1, link2, costt); } costt = MAX; temp = NLastIndex[C1].save; t = 1; EMDFS(NLastIndex, MEmergency, &costt, C1, C2, flag, &temp, MEmergency[C1].cost, &t, temp); cout << t << " " << temp << endl; delete []NLastIndex; delete []MEmergency; return 0; }
相关文章推荐
- 媒体行业过滤功能测试设计
- 机房重构之接口
- LR使用Java User协议环境报错Please add the <JDK>\bin to the path and try again
- OnCreate
- Hibernate的evict方法和clear方法的区别
- 数据结构复习之栈和队列
- 关于MFC库和CRT库冲突的分析
- Oracle 11g 环境,使用utl_smtp创建一个存储过程来发送邮件
- Throwing cards away I
- CSU 1337(费马大定理)
- 用并查集判断一个无向图中是否存在环
- DirectX11 屏幕的清除和显示
- HTML5学习笔记简明版(10):过时的元素和属性
- leetcode 042 —— Trapping Rain Water
- 关于MFC库和CRT库冲突的分析
- UVa 10763 - Foreign Exchange
- Android手机截屏
- 程序员父亲的遗产——编程十诫
- 1013. Battle Over Cities (25)
- ViewPager实现类似广告界面滚动效果