#include<bits/stdc++.h>
#define mn 100009
#define pb push_back
using namespace std;
long long n, m, S, T, U, V;
long long f[mn];
vector<long long> v[mn], l[mn];
void Dij(long long k, long long *D){
priority_queue<pair<long long,long long> > q;
q.push({0,k});
for(long long i = 1; i <= n; i++)
D[i] = 1e18, f[i] = 0;
D[k] = 0;
while(q.size()){
long long x = q.top().second;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(long long i = 0; i < v[x].size(); i++){
if(f[v[x][i]] == 0 &&
D[v[x][i]] > D[x] + l[x][i]){
D[v[x][i]] = D[x] + l[x][i];
q.push({-D[v[x][i]], v[x][i]});
}
}
}
}
long long du[mn], dv[mn], ds[mn], dt[mn], mindu[mn], mindv[mn];
void specDIJ(){
priority_queue<pair<long long,long long> > q;
q.push({0,T});
for(long long i = 1; i <= n; i++)
dt[i] = 1e18, mindu[i] = du[i], mindv[i] = dv[i] ,f[i] = 0;
dt[T] = 0;
while(q.size()){
long long x = q.top().second;
q.pop();
if(f[x]) continue;
f[x] = 1;
for(long long i = 0; i < v[x].size(); i++){
long long p = v[x][i];
if(dt[p] > dt[x] + l[x][i]){
dt[p] = dt[x] + l[x][i];
mindu[p] = min(mindu[x], du[p]);
mindv[p] = min(mindv[x], dv[p]);
q.push({-dt[p], p});
}
if(dt[p] == dt[x] + l[x][i]){
mindu[p] = min(mindu[p], mindu[x]);
mindv[p] = min(mindv[p], mindv[x]);
}
}
}
}
main(){
cin >> n >> m >> S >> T >> U >> V;
for(long long i = 0 ;i < m; i++){
long long a, b, c;
cin >> a>> b >> c;
v[a].pb(b);
v[b].pb(a);
l[a].pb(c);
l[b].pb(c);
}
Dij(S,ds);
Dij(U,du);
Dij(V,dv);
specDIJ();
long long ans = 1e18;
for(long long i = 1; i <= n; i++){
if(ds[i] + dt[i] == ds[T]){
ans = min(ans, dv[i] + mindu[i]);
ans = min(ans, du[i] + mindv[i]);
}
}
cout << min(ans, du[V]) << endl;
}
Compilation message
commuter_pass.cpp: In function 'void Dij(long long int, long long int*)':
commuter_pass.cpp:19:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v[x].size(); i++){
~~^~~~~~~~~~~~~
commuter_pass.cpp: In function 'void specDIJ()':
commuter_pass.cpp:40:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v[x].size(); i++){
~~^~~~~~~~~~~~~
commuter_pass.cpp: At global scope:
commuter_pass.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
899 ms |
26100 KB |
Output is correct |
2 |
Correct |
864 ms |
26100 KB |
Output is correct |
3 |
Correct |
933 ms |
26100 KB |
Output is correct |
4 |
Correct |
799 ms |
26100 KB |
Output is correct |
5 |
Correct |
933 ms |
26100 KB |
Output is correct |
6 |
Correct |
965 ms |
26432 KB |
Output is correct |
7 |
Correct |
899 ms |
26432 KB |
Output is correct |
8 |
Correct |
912 ms |
26432 KB |
Output is correct |
9 |
Correct |
940 ms |
26432 KB |
Output is correct |
10 |
Correct |
955 ms |
29280 KB |
Output is correct |
11 |
Correct |
419 ms |
29280 KB |
Output is correct |
12 |
Correct |
966 ms |
35864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
900 ms |
35976 KB |
Output is correct |
2 |
Correct |
1037 ms |
36000 KB |
Output is correct |
3 |
Correct |
970 ms |
36000 KB |
Output is correct |
4 |
Correct |
965 ms |
36000 KB |
Output is correct |
5 |
Correct |
1033 ms |
36016 KB |
Output is correct |
6 |
Correct |
1115 ms |
36016 KB |
Output is correct |
7 |
Correct |
946 ms |
36088 KB |
Output is correct |
8 |
Correct |
838 ms |
36088 KB |
Output is correct |
9 |
Correct |
811 ms |
36088 KB |
Output is correct |
10 |
Correct |
889 ms |
36088 KB |
Output is correct |
11 |
Correct |
411 ms |
36088 KB |
Output is correct |
12 |
Correct |
839 ms |
36088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
36088 KB |
Output is correct |
2 |
Correct |
9 ms |
36088 KB |
Output is correct |
3 |
Correct |
10 ms |
36088 KB |
Output is correct |
4 |
Correct |
68 ms |
36088 KB |
Output is correct |
5 |
Correct |
33 ms |
36088 KB |
Output is correct |
6 |
Correct |
9 ms |
36088 KB |
Output is correct |
7 |
Correct |
9 ms |
36088 KB |
Output is correct |
8 |
Correct |
11 ms |
36088 KB |
Output is correct |
9 |
Correct |
9 ms |
36088 KB |
Output is correct |
10 |
Correct |
33 ms |
36088 KB |
Output is correct |
11 |
Correct |
7 ms |
36088 KB |
Output is correct |
12 |
Correct |
7 ms |
36088 KB |
Output is correct |
13 |
Correct |
9 ms |
36088 KB |
Output is correct |
14 |
Correct |
8 ms |
36088 KB |
Output is correct |
15 |
Correct |
12 ms |
36088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
899 ms |
26100 KB |
Output is correct |
2 |
Correct |
864 ms |
26100 KB |
Output is correct |
3 |
Correct |
933 ms |
26100 KB |
Output is correct |
4 |
Correct |
799 ms |
26100 KB |
Output is correct |
5 |
Correct |
933 ms |
26100 KB |
Output is correct |
6 |
Correct |
965 ms |
26432 KB |
Output is correct |
7 |
Correct |
899 ms |
26432 KB |
Output is correct |
8 |
Correct |
912 ms |
26432 KB |
Output is correct |
9 |
Correct |
940 ms |
26432 KB |
Output is correct |
10 |
Correct |
955 ms |
29280 KB |
Output is correct |
11 |
Correct |
419 ms |
29280 KB |
Output is correct |
12 |
Correct |
966 ms |
35864 KB |
Output is correct |
13 |
Correct |
900 ms |
35976 KB |
Output is correct |
14 |
Correct |
1037 ms |
36000 KB |
Output is correct |
15 |
Correct |
970 ms |
36000 KB |
Output is correct |
16 |
Correct |
965 ms |
36000 KB |
Output is correct |
17 |
Correct |
1033 ms |
36016 KB |
Output is correct |
18 |
Correct |
1115 ms |
36016 KB |
Output is correct |
19 |
Correct |
946 ms |
36088 KB |
Output is correct |
20 |
Correct |
838 ms |
36088 KB |
Output is correct |
21 |
Correct |
811 ms |
36088 KB |
Output is correct |
22 |
Correct |
889 ms |
36088 KB |
Output is correct |
23 |
Correct |
411 ms |
36088 KB |
Output is correct |
24 |
Correct |
839 ms |
36088 KB |
Output is correct |
25 |
Correct |
40 ms |
36088 KB |
Output is correct |
26 |
Correct |
9 ms |
36088 KB |
Output is correct |
27 |
Correct |
10 ms |
36088 KB |
Output is correct |
28 |
Correct |
68 ms |
36088 KB |
Output is correct |
29 |
Correct |
33 ms |
36088 KB |
Output is correct |
30 |
Correct |
9 ms |
36088 KB |
Output is correct |
31 |
Correct |
9 ms |
36088 KB |
Output is correct |
32 |
Correct |
11 ms |
36088 KB |
Output is correct |
33 |
Correct |
9 ms |
36088 KB |
Output is correct |
34 |
Correct |
33 ms |
36088 KB |
Output is correct |
35 |
Correct |
7 ms |
36088 KB |
Output is correct |
36 |
Correct |
7 ms |
36088 KB |
Output is correct |
37 |
Correct |
9 ms |
36088 KB |
Output is correct |
38 |
Correct |
8 ms |
36088 KB |
Output is correct |
39 |
Correct |
12 ms |
36088 KB |
Output is correct |
40 |
Correct |
839 ms |
41144 KB |
Output is correct |
41 |
Correct |
887 ms |
44692 KB |
Output is correct |
42 |
Correct |
927 ms |
48860 KB |
Output is correct |
43 |
Correct |
460 ms |
48860 KB |
Output is correct |
44 |
Correct |
430 ms |
48860 KB |
Output is correct |
45 |
Correct |
871 ms |
56048 KB |
Output is correct |
46 |
Correct |
945 ms |
59300 KB |
Output is correct |
47 |
Correct |
955 ms |
64736 KB |
Output is correct |
48 |
Correct |
480 ms |
64736 KB |
Output is correct |
49 |
Correct |
861 ms |
69772 KB |
Output is correct |
50 |
Correct |
1018 ms |
72064 KB |
Output is correct |
51 |
Correct |
893 ms |
75320 KB |
Output is correct |