-
Notifications
You must be signed in to change notification settings - Fork 0
/
1003.cpp
63 lines (62 loc) · 1.18 KB
/
1003.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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
const int INF = 0x3fffffff;
int n, m, c1, c2;
struct edge{
int v, len;
edge(int vv, int ll){
v = vv;
len = ll;
}
};
vector<edge> adj[MAXN];
int weight[MAXN];
bool vis[MAXN] = {false};
int d[MAXN], w[MAXN]={0}, cnt[MAXN];
void Dijkstra(int s){
fill(d, d+MAXN, INF);
d[s] = 0;
cnt[s] = 1;
w[s] = weight[s];
for(int i=0; i<n; i++){
int u = -1, min = INF;
for(int j=0; j<n; j++){
if(!vis[j] && d[j]<min){
u = j;
min = d[j];
}
}
if(u == -1) return;
vis[u] = true;
for(int j=0; j<adj[u].size(); j++){
int v = adj[u][j].v, len = adj[u][j].len;
if(vis[v] == false){
if(d[u] + len < d[v]){
d[v] = d[u] + len;
cnt[v] = cnt[u];
w[v] = w[u] + weight[v];
}else if(d[u] + len == d[v]){
cnt[v] += cnt[u];
if(w[u] + weight[v] > w[v]){
w[v] = w[u] + weight[v];
}
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m>>c1>>c2;
for(int i=0; i<n; i++) cin>>weight[i];
for(int i=0; i<m; i++){
int u, v, l;
cin>>u>>v>>l;
adj[u].push_back(edge(v, l));
adj[v].push_back(edge(u, l));
}
Dijkstra(c1);
cout<<cnt[c2]<<' '<<w[c2];
return 0;
}