-
Notifications
You must be signed in to change notification settings - Fork 2
/
A1003-2.cpp
75 lines (69 loc) · 1.53 KB
/
A1003-2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstdio>
#define INF 0x3f3f3f3f
#define MAX 501
using namespace std;
int *dijkstra(const int (&w)[MAX][MAX], const int (&teams)[MAX], int n, int start, int end){
int dist[MAX];
bool visited[MAX];
int pathcount[MAX];
int amount[MAX];
static int result[2];
for(int i = 0; i < n; ++i){
visited[i] = false;
pathcount[i] = 0;
amount[i] = 0;
dist[i] = INF;
}
//visited[start] = true;
amount[start] = teams[start];
pathcount[start] = 1;
dist[start] = 0;
for(int i = 0; i < n; ++i){
int min = INF;
int k;
for(int j = 0; j < n; ++j){
if(visited[j] == false && dist[j] < min){
min = dist[j];
k = j;
}
}
visited[k] = true;
for(int j = 0; j < n; ++j){
if(visited[j] == false && dist[j] > dist[k] + w[k][j]){
dist[j] = dist[k] + w[k][j];
amount[j] = amount[k] + teams[j];
pathcount[j] = pathcount[k];
}else if(visited[j] == false && dist[j] == dist[k] + w[k][j]){
pathcount[j] += pathcount[k];
if(amount[j] < amount[k] + teams[j]){
amount[j] = amount[k] + teams[j];
}
}
}
}
result[0] = pathcount[end];
result[1] = amount[end];
return result;
}
int main(){
int w[MAX][MAX];
int teams[MAX];
int N, M, C1, C2;
scanf("%d%d%d%d", &N, &M, &C1, &C2);
for(int i = 0; i < N; ++i){
scanf("%d", &teams[i]);
}
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
w[i][j] = INF;
}
}
for(int i = 0; i < M; ++i){
int m, n, l;
scanf("%d%d%d", &m, &n, &l);
w[m][n] = w[n][m] = l;
}
int *r = dijkstra(w, teams, N, C1, C2);
printf("%d %d", *r, *(r + 1));
return 0;
}