/*input
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
*/
#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, u, v;
vector<pair<int, int>> ad[100010];
void dij(int fw, vector<long long>&f) {
fill(f.begin(), f.end(), 1e15);
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
q.push({0, fw}); f[fw] = 0;
while (q.size()) {
long long w; int u; tie(w, u) = q.top(); q.pop();
for (auto v : ad[u]) {
if (f[v.first] > w + v.second) {
f[v.first] = w + v.second;
q.push({w + v.second, v.first});
}
}
}
}
main() {
cin >> n >> m >> s >> t >> u >> v;
for (int i = 0; i < m; ++i) {
int x, y, w; cin >> x >> y >> w;
ad[x].push_back({y, w});
ad[y].push_back({x, w});
}
vector<long long> fs(n + 1), ft(n + 1), fu(n + 1), fv(n + 1);
dij(t, ft);
dij(u, fu);
dij(v, fv);
dij(s, fs);
long long ret = fu[v];
for (int i = 0; i < 2; ++i) {
vector<long long> f(n + 1, 1e15), pf(n + 1, 1e15);
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q; q.push({0, s}); f[s] = 0; pf[s] = fu[s];
while (q.size()) {
long long w; int u; tie(w, u) = q.top(); q.pop();
ret = min(ret, pf[u] + fv[u]);
for (auto v : ad[u]) {
if (fs[v.first] + ft[v.first] == fs[t]) {
pf[v.first] = min({pf[v.first], fu[v.first], pf[u]});
if (f[v.first] > w + v.second) {
f[v.first] = w + v.second;
q.push({w + v.second, v.first});
}
}
}
}
swap(fu, fv);
}
cout << ret;
}
Compilation message
commuter_pass.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
15272 KB |
Output is correct |
2 |
Correct |
484 ms |
13976 KB |
Output is correct |
3 |
Correct |
537 ms |
14508 KB |
Output is correct |
4 |
Correct |
466 ms |
15100 KB |
Output is correct |
5 |
Correct |
502 ms |
13908 KB |
Output is correct |
6 |
Correct |
518 ms |
15268 KB |
Output is correct |
7 |
Correct |
508 ms |
14124 KB |
Output is correct |
8 |
Correct |
510 ms |
13924 KB |
Output is correct |
9 |
Correct |
474 ms |
13832 KB |
Output is correct |
10 |
Correct |
405 ms |
13712 KB |
Output is correct |
11 |
Correct |
208 ms |
10436 KB |
Output is correct |
12 |
Correct |
485 ms |
14172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
511 ms |
14152 KB |
Output is correct |
2 |
Correct |
529 ms |
13920 KB |
Output is correct |
3 |
Correct |
507 ms |
13928 KB |
Output is correct |
4 |
Correct |
509 ms |
14076 KB |
Output is correct |
5 |
Correct |
531 ms |
17436 KB |
Output is correct |
6 |
Correct |
546 ms |
18196 KB |
Output is correct |
7 |
Correct |
610 ms |
17928 KB |
Output is correct |
8 |
Correct |
564 ms |
17424 KB |
Output is correct |
9 |
Correct |
544 ms |
17568 KB |
Output is correct |
10 |
Correct |
547 ms |
17392 KB |
Output is correct |
11 |
Correct |
226 ms |
12512 KB |
Output is correct |
12 |
Correct |
544 ms |
18152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3276 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
46 ms |
4004 KB |
Output is correct |
5 |
Correct |
23 ms |
3340 KB |
Output is correct |
6 |
Correct |
4 ms |
2636 KB |
Output is correct |
7 |
Correct |
5 ms |
2636 KB |
Output is correct |
8 |
Correct |
6 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
2636 KB |
Output is correct |
10 |
Correct |
24 ms |
3248 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
473 ms |
15272 KB |
Output is correct |
2 |
Correct |
484 ms |
13976 KB |
Output is correct |
3 |
Correct |
537 ms |
14508 KB |
Output is correct |
4 |
Correct |
466 ms |
15100 KB |
Output is correct |
5 |
Correct |
502 ms |
13908 KB |
Output is correct |
6 |
Correct |
518 ms |
15268 KB |
Output is correct |
7 |
Correct |
508 ms |
14124 KB |
Output is correct |
8 |
Correct |
510 ms |
13924 KB |
Output is correct |
9 |
Correct |
474 ms |
13832 KB |
Output is correct |
10 |
Correct |
405 ms |
13712 KB |
Output is correct |
11 |
Correct |
208 ms |
10436 KB |
Output is correct |
12 |
Correct |
485 ms |
14172 KB |
Output is correct |
13 |
Correct |
511 ms |
14152 KB |
Output is correct |
14 |
Correct |
529 ms |
13920 KB |
Output is correct |
15 |
Correct |
507 ms |
13928 KB |
Output is correct |
16 |
Correct |
509 ms |
14076 KB |
Output is correct |
17 |
Correct |
531 ms |
17436 KB |
Output is correct |
18 |
Correct |
546 ms |
18196 KB |
Output is correct |
19 |
Correct |
610 ms |
17928 KB |
Output is correct |
20 |
Correct |
564 ms |
17424 KB |
Output is correct |
21 |
Correct |
544 ms |
17568 KB |
Output is correct |
22 |
Correct |
547 ms |
17392 KB |
Output is correct |
23 |
Correct |
226 ms |
12512 KB |
Output is correct |
24 |
Correct |
544 ms |
18152 KB |
Output is correct |
25 |
Correct |
25 ms |
3276 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
46 ms |
4004 KB |
Output is correct |
29 |
Correct |
23 ms |
3340 KB |
Output is correct |
30 |
Correct |
4 ms |
2636 KB |
Output is correct |
31 |
Correct |
5 ms |
2636 KB |
Output is correct |
32 |
Correct |
6 ms |
2764 KB |
Output is correct |
33 |
Correct |
4 ms |
2636 KB |
Output is correct |
34 |
Correct |
24 ms |
3248 KB |
Output is correct |
35 |
Correct |
3 ms |
2636 KB |
Output is correct |
36 |
Correct |
3 ms |
2636 KB |
Output is correct |
37 |
Correct |
3 ms |
2636 KB |
Output is correct |
38 |
Correct |
3 ms |
2636 KB |
Output is correct |
39 |
Correct |
4 ms |
2636 KB |
Output is correct |
40 |
Correct |
499 ms |
19532 KB |
Output is correct |
41 |
Correct |
514 ms |
18196 KB |
Output is correct |
42 |
Correct |
531 ms |
18244 KB |
Output is correct |
43 |
Correct |
269 ms |
12548 KB |
Output is correct |
44 |
Correct |
306 ms |
12588 KB |
Output is correct |
45 |
Correct |
609 ms |
18592 KB |
Output is correct |
46 |
Correct |
538 ms |
18436 KB |
Output is correct |
47 |
Correct |
482 ms |
18828 KB |
Output is correct |
48 |
Correct |
255 ms |
12100 KB |
Output is correct |
49 |
Correct |
422 ms |
19032 KB |
Output is correct |
50 |
Correct |
528 ms |
17952 KB |
Output is correct |
51 |
Correct |
516 ms |
18616 KB |
Output is correct |