首页 > 其他 > 详细

1003. Emergency (25)

时间:2015-02-13 23:37:31      阅读:255      评论:0      收藏:0      [点我收藏+]

 

时间限制
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
 1 #include <stdio.h>
 2 #include<string.h>
 3 
 4 #define MAX 510
 5 int INF = 100000;
 6 int w[MAX];
 7 int wight[MAX];
 8 int d[MAX];
 9 int num[MAX];
10 int Grap[MAX][MAX];
11 bool visit[MAX];
12 
13 void Dijkstra(int begin,int NodeNum)
14 {
15     d[begin] = 0;
16     w[begin] = wight[begin];
17     num[begin] = 1;
18     for(int i = 0; i < NodeNum ;i++)
19     {
20         int index = -1;
21         int Min = INF ;
22         for(int j = 0 ;j < NodeNum;j++)  //找出距离起点最近节点
23         {
24             if(visit[j] == false && d[j] < Min)
25             {
26                 index = j;
27                 Min = d[j];
28             }
29         }
30 
31         if(index == -1) //如果找不出小于INF的节点,说明剩下的节点都与起点不连通
32             return ;
33         visit[index] = true ;
34 
35         for(int v = 0;v < NodeNum;v++)
36         {
37             if(visit[v] == false && Grap[index][v]!=INF)
38             {
39                 if(d[index] + Grap[index][v] < d[v])
40                 {
41                     d[v] = d[index] + Grap[index][v];
42                     w[v] = w[index] + wight[v];
43                     num[v] = num[index];
44                 }
45                 else if(d[index] + Grap[index][v] == d[v])
46                 {
47                     if(w[index] + wight[v] > w[v])
48                         w[v] = w[index] + wight[v];
49                     num[v] = num[index] + num[v]; 
50                 }
51             }
52         }
53     }
54 }
55 int main()
56 {
57     int i,NodeNum,EdgNum,Begin,End;
58     scanf("%d%d%d%d",&NodeNum,&EdgNum,&Begin,&End);
59 
60     for(i = 0 ;i < NodeNum ;i++)
61     {
62         for(int j = 0 ; j < NodeNum ; j++)
63             Grap[i][j] = INF ;
64 
65         w[i] = 0;
66         num[i] = 0;
67         d[i] = INF ;
68         visit[i] = false;
69     }
70 
71 
72     for(i = 0 ; i < NodeNum ; i ++)
73     {
74         scanf("%d",&wight[i]);
75     }
76     int x,y;
77     for( i = 0;i< EdgNum ;i++)
78     {
79         scanf("%d%d",&x,&y);
80         scanf("%d",&Grap[x][y]);
81         Grap[y][x] = Grap[x][y];
82     }
83 
84     Dijkstra(Begin,NodeNum);
85     printf("%d %d\n",num[End],w[End]);
86     return 0;
87 }

 



1003. Emergency (25)

原文:http://www.cnblogs.com/xiaoyesoso/p/4290991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!