#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int max(int i, int j) { return i > j ? i : j; }
int min(int i, int j) { return i < j ? i : j; }
#define N 200005
const int oo = 1e9;
int n, m, a[N], *eh[N], eo[N], to, dp[N], dq[N], *focus, t[N * 2], z = oo;
int Lt(int i, int j) { return focus[i] < focus[j]; }
int Min(int i, int j) { return Lt(i, j) ? i : j; }
void pul(int i) { t[i] = Min(t[i * 2], t[i * 2 + 1]); }
void fix(int i) { for (i += n; i /= 2; ) pul(i); }
void pus(int i, int j) {
int o = eo[i]++;
if (!o) eh[i] = (int*)malloc(sizeof **eh * 2);
else if (!(o & (o - 1))) eh[i] = (int*)realloc(eh[i], 2 * o * sizeof **eh);
eh[i][o] = j;
}
void Dijkstra(int src, int *dp) {
focus = dp;
for (int i = 0; i < n; ++i) dp[i] = oo, t[i + n] = i;
dp[src] = 0;
dp[n] = oo + 1;
for (int i = n; --i;) pul(i);
for (int i = 1; i <= n; ++i) {
int u = t[1];
t[u + n] = n;
fix(u);
for (int v, j = 0; j < eo[u]; ++j) {
v = eh[u][j];
int nc = max(dp[u] + 1, a[v]);
if (t[v + n] == v && nc < dp[v]) {
dp[v] = nc;
fix(v);
}
}
}
}
int main() {
srand(time(0));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%d", a + i);
for (int u, v, i = 0; i < m; ++i)
scanf("%d%d", &u, &v), pus(--u, --v), pus(v, u);
Dijkstra(0, dp);
Dijkstra(n - 1, dq);
for (int i = 0; i < n; ++i) {
z = min(z, max(dp[i], dq[i]) * 2);
for (int k = 0; k < eo[i]; ++k) {
int j = eh[i][k];
z = min(z, 2 * max(dp[i], dq[j]) + 1);
}
}
printf("%d", z);
}
Compilation message
Main.c: In function 'main':
Main.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:51:30: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | for (int i = 0; i < n; ++i) scanf("%d", a + i);
| ^~~~~~~~~~~~~~~~~~
Main.c:53:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d%d", &u, &v), pus(--u, --v), pus(v, u);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
107 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12872 KB |
Output is correct |
4 |
Correct |
104 ms |
13148 KB |
Output is correct |
5 |
Correct |
107 ms |
12728 KB |
Output is correct |
6 |
Correct |
104 ms |
12872 KB |
Output is correct |
7 |
Correct |
104 ms |
12872 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2504 KB |
Output is correct |
7 |
Correct |
3 ms |
2384 KB |
Output is correct |
8 |
Correct |
2 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
2384 KB |
Output is correct |
10 |
Correct |
2 ms |
2384 KB |
Output is correct |
11 |
Correct |
2 ms |
2384 KB |
Output is correct |
12 |
Correct |
2 ms |
2384 KB |
Output is correct |
13 |
Correct |
2 ms |
2384 KB |
Output is correct |
14 |
Correct |
2 ms |
2552 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2504 KB |
Output is correct |
7 |
Correct |
3 ms |
2384 KB |
Output is correct |
8 |
Correct |
2 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
2384 KB |
Output is correct |
10 |
Correct |
2 ms |
2384 KB |
Output is correct |
11 |
Correct |
2 ms |
2384 KB |
Output is correct |
12 |
Correct |
2 ms |
2384 KB |
Output is correct |
13 |
Correct |
2 ms |
2384 KB |
Output is correct |
14 |
Correct |
2 ms |
2552 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
2 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2384 KB |
Output is correct |
24 |
Correct |
2 ms |
2384 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2384 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2640 KB |
Output is correct |
30 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
107 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12872 KB |
Output is correct |
4 |
Correct |
104 ms |
13148 KB |
Output is correct |
5 |
Correct |
107 ms |
12728 KB |
Output is correct |
6 |
Correct |
104 ms |
12872 KB |
Output is correct |
7 |
Correct |
104 ms |
12872 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
2 ms |
2504 KB |
Output is correct |
15 |
Correct |
3 ms |
2384 KB |
Output is correct |
16 |
Correct |
2 ms |
2384 KB |
Output is correct |
17 |
Correct |
2 ms |
2384 KB |
Output is correct |
18 |
Correct |
2 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
2 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2552 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2816 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2384 KB |
Output is correct |
28 |
Correct |
2 ms |
2384 KB |
Output is correct |
29 |
Correct |
2 ms |
2384 KB |
Output is correct |
30 |
Correct |
2 ms |
2384 KB |
Output is correct |
31 |
Correct |
2 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2384 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2384 KB |
Output is correct |
35 |
Correct |
2 ms |
2384 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 ms |
2640 KB |
Output is correct |
38 |
Correct |
2 ms |
2640 KB |
Output is correct |
39 |
Correct |
158 ms |
12804 KB |
Output is correct |
40 |
Correct |
129 ms |
12872 KB |
Output is correct |
41 |
Correct |
118 ms |
12884 KB |
Output is correct |
42 |
Correct |
138 ms |
12872 KB |
Output is correct |
43 |
Correct |
125 ms |
12876 KB |
Output is correct |
44 |
Correct |
124 ms |
12872 KB |
Output is correct |
45 |
Correct |
130 ms |
12964 KB |
Output is correct |
46 |
Correct |
134 ms |
12880 KB |
Output is correct |
47 |
Correct |
140 ms |
12872 KB |
Output is correct |
48 |
Correct |
141 ms |
12744 KB |
Output is correct |
49 |
Correct |
199 ms |
12876 KB |
Output is correct |
50 |
Correct |
153 ms |
12872 KB |
Output is correct |
51 |
Correct |
150 ms |
12896 KB |
Output is correct |
52 |
Correct |
216 ms |
13352 KB |
Output is correct |
53 |
Correct |
159 ms |
13384 KB |
Output is correct |
54 |
Correct |
173 ms |
13388 KB |
Output is correct |
55 |
Correct |
201 ms |
13380 KB |
Output is correct |
56 |
Correct |
208 ms |
14920 KB |
Output is correct |
57 |
Correct |
210 ms |
14920 KB |
Output is correct |
58 |
Correct |
226 ms |
14920 KB |
Output is correct |
59 |
Correct |
268 ms |
14920 KB |
Output is correct |
60 |
Correct |
231 ms |
14816 KB |
Output is correct |
61 |
Correct |
271 ms |
15016 KB |
Output is correct |
62 |
Correct |
184 ms |
14920 KB |
Output is correct |
63 |
Correct |
204 ms |
14912 KB |
Output is correct |
64 |
Correct |
206 ms |
14920 KB |
Output is correct |
65 |
Correct |
217 ms |
14776 KB |
Output is correct |
66 |
Correct |
186 ms |
14920 KB |
Output is correct |
67 |
Correct |
192 ms |
14888 KB |
Output is correct |