-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpat-1003.cpp
More file actions
67 lines (64 loc) · 1.36 KB
/
Copy pathpat-1003.cpp
File metadata and controls
67 lines (64 loc) · 1.36 KB
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
#include <cstdio>
#include <vector>
#include <deque>
#include <limits>
#include <algorithm>
using namespace std;
const int N = 500;
bool known[N] = {0};
long dist_now[N];
long hand_now[N] = {0};
int counts[N] = {0};
int map[N][N] = {0};
int hand[N] = {0};
bool comp(int a, int b) {
if (dist_now[a] < dist_now[b])
return true;
return false;
}
int main() {
int n, m, c1, c2;
scanf("%d %d %d %d", &n, &m, &c1, &c2);
for (int i=0;i<n;i++) {
scanf("%d", hand + i);
dist_now[i] = numeric_limits<long>::max();
}
for (int i=0;i<m;i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
map[a][b] = map[b][a] = c;
}
deque<int> q;
dist_now[c1] = 0;
counts[c1] = 1;
hand_now[c1] = hand[c1];
q.push_back(c1);
for (int i=0;i<n;i++) {
if (i != c1) q.push_back(i);
}
while (!q.empty()) {
int now = q.front();
if (dist_now[now] > dist_now[c2]) break;
q.pop_front();
known[now] = true;
for (int i = 0; i < n; i++) {
if (!known[i] && map[now][i] != 0) {
int dis = dist_now[now] + map[now][i];
int han = hand_now[now] + hand[i];
if (dis < dist_now[i]) {
dist_now[i] = dis;
hand_now[i] = han;
counts[i] = counts[now];
}
else if (dis == dist_now[i]) {
counts[i] += counts[now];
if (hand_now[i] < han)
hand_now[i] = han;
}
}
}
sort(q.begin(), q.end(), comp);
}
printf("%d %ld\n", counts[c2], hand_now[c2]);
return 0;
}