# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1063110 |
2024-08-17T14:18:36 Z |
_8_8_ |
Olympic Bus (JOI20_ho_t4) |
C++17 |
|
649 ms |
8720 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 12, MOD = (int)1e9 + 7;
#define int ll
const ll inf = 1e16;
int n,m;
int U[N],V[N],C[N],D[N];
void dijkstra(int ver,vector<ll> &d,vector<int> &pr) {
d.resize(n);
pr.resize(n);
for(int i = 0;i < n;i++) {
d[i] = inf;
}
d[ver] = 0;
vector<int> vis(n,0);
vector<vector<int>> g;g.resize(n);
for(int i = 0;i < m;++i) {
g[U[i]].push_back(i);
}
for(int i = 0;i < n;i++) {
int v = -1;
for(int j = 0;j < n;j++) {
if(vis[j]) continue;
if(v == -1 || d[j] < d[v]) {
v = j;
}
}
vis[v] = 1;
for(int t:g[v]) {
int to = V[t],w = C[t];
if(d[to] > d[v] + w) {
d[to] = d[v] + w;
pr[to] = t;
}
}
}
}
vector<ll> d[N];
vector<int> p[N];
ll res = inf;
bool in[N];
void test() {
cin >> n >> m;
for(int i = 0;i < m;i++) {
cin >> U[i] >> V[i] >> C[i] >> D[i];
U[i]--;V[i]--;
}
for(int i = 0;i < n;++i) {
dijkstra(i,d[i],p[i]);
}
ll x = d[0][n - 1],y = d[n - 1][0];
res = x + y;
vector<ll> bfd;
vector<int> bfp;
auto make = [&](int j){
in[j] = 1;
swap(V[j],U[j]);
ll nv = D[j];
dijkstra(0,bfd,bfp);
nv += bfd[n - 1];
dijkstra(n - 1,bfd,bfp);
nv += bfd[0];
res = min(res,nv);
swap(V[j],U[j]);
};
for(int i = 0;i < n;i++) {
if(d[0][i] != inf && i != 0) {
make(p[0][i]);
}
if(d[n - 1][i] != inf && i != n - 1) {
make(p[n - 1][i]);
}
}
for(int i = 0;i < m;i++) {
if(in[i]) continue;
swap(U[i],V[i]);
ll val = min(x,d[0][U[i]] + d[V[i]][n - 1] + C[i]) + D[i];
val += min(y,d[n - 1][U[i]] + d[V[i]][0] + C[i]);
res = min(res,val);
}
if(res >= inf) res = -1;
cout << res << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
// cin >> t;
while(t--) {
test();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
5724 KB |
Output is correct |
2 |
Correct |
17 ms |
5724 KB |
Output is correct |
3 |
Correct |
101 ms |
5724 KB |
Output is correct |
4 |
Correct |
91 ms |
5720 KB |
Output is correct |
5 |
Correct |
7 ms |
5208 KB |
Output is correct |
6 |
Correct |
20 ms |
5748 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
93 ms |
5848 KB |
Output is correct |
11 |
Correct |
95 ms |
5720 KB |
Output is correct |
12 |
Correct |
105 ms |
5836 KB |
Output is correct |
13 |
Correct |
69 ms |
5720 KB |
Output is correct |
14 |
Correct |
73 ms |
5720 KB |
Output is correct |
15 |
Correct |
76 ms |
5852 KB |
Output is correct |
16 |
Correct |
100 ms |
5784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
8216 KB |
Output is correct |
2 |
Correct |
634 ms |
8204 KB |
Output is correct |
3 |
Correct |
590 ms |
8296 KB |
Output is correct |
4 |
Correct |
106 ms |
5812 KB |
Output is correct |
5 |
Correct |
87 ms |
5720 KB |
Output is correct |
6 |
Correct |
22 ms |
5768 KB |
Output is correct |
7 |
Correct |
23 ms |
5748 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
367 ms |
8380 KB |
Output is correct |
10 |
Correct |
389 ms |
8204 KB |
Output is correct |
11 |
Correct |
498 ms |
8492 KB |
Output is correct |
12 |
Correct |
502 ms |
8236 KB |
Output is correct |
13 |
Correct |
480 ms |
8212 KB |
Output is correct |
14 |
Correct |
480 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
5848 KB |
Output is correct |
2 |
Correct |
30 ms |
5724 KB |
Output is correct |
3 |
Correct |
458 ms |
7664 KB |
Output is correct |
4 |
Correct |
23 ms |
5792 KB |
Output is correct |
5 |
Correct |
580 ms |
8192 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
4 ms |
4956 KB |
Output is correct |
8 |
Correct |
357 ms |
8196 KB |
Output is correct |
9 |
Correct |
386 ms |
8200 KB |
Output is correct |
10 |
Correct |
466 ms |
8240 KB |
Output is correct |
11 |
Correct |
460 ms |
8192 KB |
Output is correct |
12 |
Correct |
508 ms |
8248 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
537 ms |
8564 KB |
Output is correct |
20 |
Correct |
473 ms |
8544 KB |
Output is correct |
21 |
Correct |
538 ms |
8244 KB |
Output is correct |
22 |
Correct |
505 ms |
8376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
5724 KB |
Output is correct |
2 |
Correct |
17 ms |
5724 KB |
Output is correct |
3 |
Correct |
101 ms |
5724 KB |
Output is correct |
4 |
Correct |
91 ms |
5720 KB |
Output is correct |
5 |
Correct |
7 ms |
5208 KB |
Output is correct |
6 |
Correct |
20 ms |
5748 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
93 ms |
5848 KB |
Output is correct |
11 |
Correct |
95 ms |
5720 KB |
Output is correct |
12 |
Correct |
105 ms |
5836 KB |
Output is correct |
13 |
Correct |
69 ms |
5720 KB |
Output is correct |
14 |
Correct |
73 ms |
5720 KB |
Output is correct |
15 |
Correct |
76 ms |
5852 KB |
Output is correct |
16 |
Correct |
100 ms |
5784 KB |
Output is correct |
17 |
Correct |
646 ms |
8216 KB |
Output is correct |
18 |
Correct |
634 ms |
8204 KB |
Output is correct |
19 |
Correct |
590 ms |
8296 KB |
Output is correct |
20 |
Correct |
106 ms |
5812 KB |
Output is correct |
21 |
Correct |
87 ms |
5720 KB |
Output is correct |
22 |
Correct |
22 ms |
5768 KB |
Output is correct |
23 |
Correct |
23 ms |
5748 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
367 ms |
8380 KB |
Output is correct |
26 |
Correct |
389 ms |
8204 KB |
Output is correct |
27 |
Correct |
498 ms |
8492 KB |
Output is correct |
28 |
Correct |
502 ms |
8236 KB |
Output is correct |
29 |
Correct |
480 ms |
8212 KB |
Output is correct |
30 |
Correct |
480 ms |
8556 KB |
Output is correct |
31 |
Correct |
120 ms |
5848 KB |
Output is correct |
32 |
Correct |
30 ms |
5724 KB |
Output is correct |
33 |
Correct |
458 ms |
7664 KB |
Output is correct |
34 |
Correct |
23 ms |
5792 KB |
Output is correct |
35 |
Correct |
580 ms |
8192 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
4 ms |
4956 KB |
Output is correct |
38 |
Correct |
357 ms |
8196 KB |
Output is correct |
39 |
Correct |
386 ms |
8200 KB |
Output is correct |
40 |
Correct |
466 ms |
8240 KB |
Output is correct |
41 |
Correct |
460 ms |
8192 KB |
Output is correct |
42 |
Correct |
508 ms |
8248 KB |
Output is correct |
43 |
Correct |
2 ms |
4952 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
537 ms |
8564 KB |
Output is correct |
50 |
Correct |
473 ms |
8544 KB |
Output is correct |
51 |
Correct |
538 ms |
8244 KB |
Output is correct |
52 |
Correct |
505 ms |
8376 KB |
Output is correct |
53 |
Correct |
573 ms |
8320 KB |
Output is correct |
54 |
Correct |
600 ms |
8312 KB |
Output is correct |
55 |
Correct |
649 ms |
8716 KB |
Output is correct |
56 |
Correct |
98 ms |
5844 KB |
Output is correct |
57 |
Correct |
92 ms |
5856 KB |
Output is correct |
58 |
Correct |
498 ms |
8236 KB |
Output is correct |
59 |
Correct |
485 ms |
7720 KB |
Output is correct |
60 |
Correct |
472 ms |
7816 KB |
Output is correct |
61 |
Correct |
490 ms |
8348 KB |
Output is correct |
62 |
Correct |
467 ms |
7696 KB |
Output is correct |
63 |
Correct |
514 ms |
8080 KB |
Output is correct |
64 |
Correct |
557 ms |
7720 KB |
Output is correct |
65 |
Correct |
615 ms |
7720 KB |
Output is correct |
66 |
Correct |
578 ms |
8248 KB |
Output is correct |
67 |
Correct |
12 ms |
7216 KB |
Output is correct |
68 |
Correct |
349 ms |
8612 KB |
Output is correct |
69 |
Correct |
351 ms |
8192 KB |
Output is correct |
70 |
Correct |
508 ms |
8720 KB |
Output is correct |
71 |
Correct |
504 ms |
8192 KB |
Output is correct |
72 |
Correct |
489 ms |
8388 KB |
Output is correct |
73 |
Correct |
490 ms |
8244 KB |
Output is correct |
74 |
Correct |
499 ms |
8232 KB |
Output is correct |