# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779584 |
2023-07-11T14:37:02 Z |
1bin |
Olympic Bus (JOI20_ho_t4) |
C++14 |
|
116 ms |
5980 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const ll inf = 1e18;
const int MX = 5e4 + 5;
ll n, m, a[MX], b[MX], c[MX], d[MX], ans, chk[2][MX], mnd[2], d1, d2, D[4][205];
vector<pair<ll, ll>> adj[205], rev[205];
ll dijk(int s, int e, int f){
int t = n + 1 - s;
vector<ll> dist(n + 1, inf);
vector<int> E(n + 1, 0), vis(n + 1, 0);
dist[s] = 0;
while(1){
ll mn = inf, x;
for(int i = 1; i <= n; i++)
if(!vis[i] && dist[i] < mn) mn = dist[i], x = i;
if(mn == inf) break;
vis[x] = 1;
if(f & 1){
for(auto&[nx, ix] : rev[x])
if(ix != e && dist[x] + c[ix] < dist[nx]) dist[nx] = dist[x] + c[ix], E[nx] = ix;
}
else{
for(auto&[nx, ix] : adj[x])
if(ix != e && dist[x] + c[ix] < dist[nx]) dist[nx] = dist[x] + c[ix], E[nx] = ix;
}
}
if(f < 4) {
for(int i = 1; i <= n; i++) D[f][i] = dist[i];
if(f % 2 == 0 && dist[t] != inf){
f >>= 1;
for(int x = t; x != s; x = a[E[x]]) chk[f][E[x]] = 1;
}
}
return dist[t];
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a[i] >> b[i] >> c[i] >> d[i];
adj[a[i]].emplace_back(b[i], i);
rev[b[i]].emplace_back(a[i], i);
}
dijk(1, -1, 0);
dijk(n, -1, 1);
dijk(n, -1, 2);
dijk(1, -1, 3);
mnd[0] = D[0][n];
mnd[1] = D[2][1];
ans = mnd[0] + mnd[1];
for(int i = 0; i < m; i++){
adj[b[i]].emplace_back(a[i], m);
c[m] = c[i];
if(!chk[0][i]) d1 = min(mnd[0], D[0][b[i]] + c[i] + D[1][a[i]]);
else d1 = dijk(1, i, 4);
if(!chk[1][i]) d2 = min(mnd[1], D[2][b[i]] + c[i] + D[3][a[i]]);
else d2 = dijk(n, i, 4);
ans = min(ans, d1 + d2 + d[i]);
adj[b[i]].pop_back();
}
cout << (ans >= inf ? -1 : ans);
return 0;
}
Compilation message
ho_t4.cpp: In function 'll dijk(int, int, int)':
ho_t4.cpp:24:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | for(auto&[nx, ix] : rev[x])
| ^
ho_t4.cpp:28:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto&[nx, ix] : adj[x])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
38 ms |
468 KB |
Output is correct |
11 |
Correct |
30 ms |
468 KB |
Output is correct |
12 |
Correct |
30 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
412 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
4620 KB |
Output is correct |
2 |
Correct |
21 ms |
4608 KB |
Output is correct |
3 |
Correct |
26 ms |
4564 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
15 ms |
4424 KB |
Output is correct |
10 |
Correct |
15 ms |
5532 KB |
Output is correct |
11 |
Correct |
17 ms |
5736 KB |
Output is correct |
12 |
Correct |
16 ms |
5716 KB |
Output is correct |
13 |
Correct |
16 ms |
5716 KB |
Output is correct |
14 |
Correct |
25 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
3364 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
14 ms |
4436 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
18 ms |
4436 KB |
Output is correct |
9 |
Correct |
19 ms |
5392 KB |
Output is correct |
10 |
Correct |
14 ms |
5332 KB |
Output is correct |
11 |
Correct |
14 ms |
5464 KB |
Output is correct |
12 |
Correct |
18 ms |
5464 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
14 ms |
5608 KB |
Output is correct |
20 |
Correct |
14 ms |
5380 KB |
Output is correct |
21 |
Correct |
14 ms |
5460 KB |
Output is correct |
22 |
Correct |
14 ms |
5384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
38 ms |
468 KB |
Output is correct |
11 |
Correct |
30 ms |
468 KB |
Output is correct |
12 |
Correct |
30 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
412 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
15 ms |
4620 KB |
Output is correct |
18 |
Correct |
21 ms |
4608 KB |
Output is correct |
19 |
Correct |
26 ms |
4564 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
15 ms |
4424 KB |
Output is correct |
26 |
Correct |
15 ms |
5532 KB |
Output is correct |
27 |
Correct |
17 ms |
5736 KB |
Output is correct |
28 |
Correct |
16 ms |
5716 KB |
Output is correct |
29 |
Correct |
16 ms |
5716 KB |
Output is correct |
30 |
Correct |
25 ms |
5980 KB |
Output is correct |
31 |
Correct |
2 ms |
516 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
11 ms |
3364 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
14 ms |
4436 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
18 ms |
4436 KB |
Output is correct |
39 |
Correct |
19 ms |
5392 KB |
Output is correct |
40 |
Correct |
14 ms |
5332 KB |
Output is correct |
41 |
Correct |
14 ms |
5464 KB |
Output is correct |
42 |
Correct |
18 ms |
5464 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
14 ms |
5608 KB |
Output is correct |
50 |
Correct |
14 ms |
5380 KB |
Output is correct |
51 |
Correct |
14 ms |
5460 KB |
Output is correct |
52 |
Correct |
14 ms |
5384 KB |
Output is correct |
53 |
Correct |
42 ms |
5420 KB |
Output is correct |
54 |
Correct |
18 ms |
5360 KB |
Output is correct |
55 |
Correct |
16 ms |
5456 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
78 ms |
4820 KB |
Output is correct |
59 |
Correct |
66 ms |
4820 KB |
Output is correct |
60 |
Correct |
74 ms |
4796 KB |
Output is correct |
61 |
Correct |
59 ms |
4796 KB |
Output is correct |
62 |
Correct |
79 ms |
4740 KB |
Output is correct |
63 |
Correct |
72 ms |
4820 KB |
Output is correct |
64 |
Correct |
116 ms |
5132 KB |
Output is correct |
65 |
Correct |
98 ms |
5204 KB |
Output is correct |
66 |
Correct |
91 ms |
5120 KB |
Output is correct |
67 |
Correct |
11 ms |
3880 KB |
Output is correct |
68 |
Correct |
15 ms |
5584 KB |
Output is correct |
69 |
Correct |
15 ms |
5588 KB |
Output is correct |
70 |
Correct |
18 ms |
5600 KB |
Output is correct |
71 |
Correct |
17 ms |
5576 KB |
Output is correct |
72 |
Correct |
20 ms |
5648 KB |
Output is correct |
73 |
Correct |
17 ms |
5620 KB |
Output is correct |
74 |
Correct |
17 ms |
5700 KB |
Output is correct |