# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
224041 |
2020-04-17T05:48:48 Z |
hihi |
Olympic Bus (JOI20_ho_t4) |
C++11 |
|
117 ms |
4352 KB |
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
constexpr int INF = 2001001001;
constexpr int MAX_N = 200;
template <class T> bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
struct edge {
int v, c, i;
edge(int iv, int ic, int ii) {
v = iv;
c = ic;
i = ii;
}
};
void dijkstra(int n, const vector<edge> *e, int *w, bool *used, int s, int t) {
int pv[n], pe[n];
fill(w, w + n, INF);
w[s] = 0;
bool fin[n];
fill(fin, fin + n, false);
for (;;) {
int p = -1;
int mn = INF;
for (int j = 0; j < n; j++) {
if (!fin[j] && chmin(mn, w[j])) p = j;
}
if (p == -1) break;
for (edge g : e[p]) {
if (chmin(w[g.v], w[p] + g.c)) {
pv[g.v] = p;
pe[g.v] = g.i;
}
}
fin[p] = true;
}
if (w[t] < INF) {
for (; t != s; t = pv[t]) {
used[pe[t]] = true;
}
}
}
int W[MAX_N + 1];
int dijkstra(int n, const vector<edge> *e, const vector<edge> *f, int i, int s, int t) {
fill(W, W + n, INF);
W[s] = 0;
for (;;) {
int p = -1;
int mn = INF;
for (int j = 0; j < n; j++) {
if (W[j] >= 0 && chmin(mn, W[j])) p = j;
}
if (p == -1 || p == t) break;
for (edge g : e[p]) {
if (g.i == i) continue;
chmin(W[g.v], W[p] + g.c);
}
W[p] = -1;
}
return W[t];
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<edge> e[2][n];
int u[m], v[m], c[m], d[m];
for (int i = 0; i < m; i++) {
scanf("%d%d%d%d", u + i, v + i, c + i, d + i);
u[i]--;
v[i]--;
e[0][u[i]].push_back(edge(v[i], c[i], i));
e[1][v[i]].push_back(edge(u[i], c[i], i));
}
bool used[2][m];
bool dum[m];
fill(used[0], used[2], false);
int x[2][n], y[2][n];
dijkstra(n, e[0], x[0], used[0], 0, n - 1);
dijkstra(n, e[0], x[1], used[1], n - 1, 0);
dijkstra(n, e[1], y[0], dum, n - 1, 0);
dijkstra(n, e[1], y[1], dum, 0, n - 1);
int w[2] = {x[0][n - 1], x[1][0]};
ll ans = (ll)w[0] + w[1];
for (int i = 0; i < m; i++) {
ll tmp = d[i];
for(int b = 0; b < 2; b++) {
if(used[b][i]) {
tmp += dijkstra(n, e[b], e[!b], i, 0, n - 1);
} else {
tmp += min((ll)w[b], (ll)c[i] + x[b][v[i]] + y[b][u[i]]);
}
}
chmin(ans, tmp);
}
if (ans >= INF) ans = -1;
printf("%lld\n", ans);
return 0;
}
Compilation message
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
ho_t4.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", u + i, v + i, c + i, d + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
308 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
26 ms |
384 KB |
Output is correct |
11 |
Correct |
20 ms |
384 KB |
Output is correct |
12 |
Correct |
23 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
4216 KB |
Output is correct |
2 |
Correct |
34 ms |
4088 KB |
Output is correct |
3 |
Correct |
39 ms |
4096 KB |
Output is correct |
4 |
Correct |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
35 ms |
4064 KB |
Output is correct |
10 |
Correct |
45 ms |
4088 KB |
Output is correct |
11 |
Correct |
43 ms |
4216 KB |
Output is correct |
12 |
Correct |
35 ms |
4216 KB |
Output is correct |
13 |
Correct |
35 ms |
4216 KB |
Output is correct |
14 |
Correct |
36 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
27 ms |
3072 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
32 ms |
3968 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
30 ms |
3960 KB |
Output is correct |
9 |
Correct |
31 ms |
3968 KB |
Output is correct |
10 |
Correct |
36 ms |
3968 KB |
Output is correct |
11 |
Correct |
35 ms |
4072 KB |
Output is correct |
12 |
Correct |
35 ms |
4088 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
30 ms |
4096 KB |
Output is correct |
20 |
Correct |
34 ms |
4088 KB |
Output is correct |
21 |
Correct |
33 ms |
4092 KB |
Output is correct |
22 |
Correct |
31 ms |
3968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
308 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
26 ms |
384 KB |
Output is correct |
11 |
Correct |
20 ms |
384 KB |
Output is correct |
12 |
Correct |
23 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
32 ms |
4216 KB |
Output is correct |
18 |
Correct |
34 ms |
4088 KB |
Output is correct |
19 |
Correct |
39 ms |
4096 KB |
Output is correct |
20 |
Correct |
7 ms |
512 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
6 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
35 ms |
4064 KB |
Output is correct |
26 |
Correct |
45 ms |
4088 KB |
Output is correct |
27 |
Correct |
43 ms |
4216 KB |
Output is correct |
28 |
Correct |
35 ms |
4216 KB |
Output is correct |
29 |
Correct |
35 ms |
4216 KB |
Output is correct |
30 |
Correct |
36 ms |
4352 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
27 ms |
3072 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
32 ms |
3968 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
5 ms |
256 KB |
Output is correct |
38 |
Correct |
30 ms |
3960 KB |
Output is correct |
39 |
Correct |
31 ms |
3968 KB |
Output is correct |
40 |
Correct |
36 ms |
3968 KB |
Output is correct |
41 |
Correct |
35 ms |
4072 KB |
Output is correct |
42 |
Correct |
35 ms |
4088 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
256 KB |
Output is correct |
45 |
Correct |
4 ms |
256 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
4 ms |
256 KB |
Output is correct |
49 |
Correct |
30 ms |
4096 KB |
Output is correct |
50 |
Correct |
34 ms |
4088 KB |
Output is correct |
51 |
Correct |
33 ms |
4092 KB |
Output is correct |
52 |
Correct |
31 ms |
3968 KB |
Output is correct |
53 |
Correct |
33 ms |
4072 KB |
Output is correct |
54 |
Correct |
37 ms |
4120 KB |
Output is correct |
55 |
Correct |
33 ms |
4088 KB |
Output is correct |
56 |
Correct |
6 ms |
384 KB |
Output is correct |
57 |
Correct |
6 ms |
384 KB |
Output is correct |
58 |
Correct |
68 ms |
3196 KB |
Output is correct |
59 |
Correct |
61 ms |
3200 KB |
Output is correct |
60 |
Correct |
67 ms |
3208 KB |
Output is correct |
61 |
Correct |
51 ms |
3200 KB |
Output is correct |
62 |
Correct |
62 ms |
3200 KB |
Output is correct |
63 |
Correct |
66 ms |
3368 KB |
Output is correct |
64 |
Correct |
117 ms |
3448 KB |
Output is correct |
65 |
Correct |
102 ms |
3320 KB |
Output is correct |
66 |
Correct |
93 ms |
3456 KB |
Output is correct |
67 |
Correct |
31 ms |
3132 KB |
Output is correct |
68 |
Correct |
42 ms |
4088 KB |
Output is correct |
69 |
Correct |
34 ms |
4088 KB |
Output is correct |
70 |
Correct |
37 ms |
4088 KB |
Output is correct |
71 |
Correct |
37 ms |
4096 KB |
Output is correct |
72 |
Correct |
35 ms |
4216 KB |
Output is correct |
73 |
Correct |
43 ms |
4348 KB |
Output is correct |
74 |
Correct |
36 ms |
4344 KB |
Output is correct |