#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) {
int x = 2 * max(dp[i], dq[i]);
z = min(z, x);
for (int k = 0; k < eo[i]; ++k) {
int j = eh[i][k];
x = 2 * max(dp[i], dq[j]) + 1;
z = min(z, x);
}
}
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);
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
114 ms |
16084 KB |
Output is correct |
3 |
Correct |
117 ms |
16340 KB |
Output is correct |
4 |
Correct |
116 ms |
16712 KB |
Output is correct |
5 |
Correct |
122 ms |
16968 KB |
Output is correct |
6 |
Correct |
117 ms |
17164 KB |
Output is correct |
7 |
Correct |
126 ms |
17224 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2436 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2896 KB |
Output is correct |
9 |
Correct |
2 ms |
2496 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
4 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
3 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2436 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2896 KB |
Output is correct |
9 |
Correct |
2 ms |
2496 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
4 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
3 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
3 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
3 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2556 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
3 ms |
2640 KB |
Output is correct |
29 |
Correct |
3 ms |
2640 KB |
Output is correct |
30 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
114 ms |
16084 KB |
Output is correct |
3 |
Correct |
117 ms |
16340 KB |
Output is correct |
4 |
Correct |
116 ms |
16712 KB |
Output is correct |
5 |
Correct |
122 ms |
16968 KB |
Output is correct |
6 |
Correct |
117 ms |
17164 KB |
Output is correct |
7 |
Correct |
126 ms |
17224 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 |
2436 KB |
Output is correct |
14 |
Correct |
2 ms |
2640 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2896 KB |
Output is correct |
17 |
Correct |
2 ms |
2496 KB |
Output is correct |
18 |
Correct |
2 ms |
2640 KB |
Output is correct |
19 |
Correct |
2 ms |
2640 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
4 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
3 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
1 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
2 ms |
2640 KB |
Output is correct |
30 |
Correct |
3 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2556 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
2 ms |
2640 KB |
Output is correct |
36 |
Correct |
3 ms |
2640 KB |
Output is correct |
37 |
Correct |
3 ms |
2640 KB |
Output is correct |
38 |
Correct |
2 ms |
2640 KB |
Output is correct |
39 |
Correct |
169 ms |
17224 KB |
Output is correct |
40 |
Correct |
148 ms |
16388 KB |
Output is correct |
41 |
Correct |
134 ms |
16300 KB |
Output is correct |
42 |
Correct |
132 ms |
16456 KB |
Output is correct |
43 |
Correct |
145 ms |
16456 KB |
Output is correct |
44 |
Correct |
172 ms |
16388 KB |
Output is correct |
45 |
Correct |
146 ms |
16200 KB |
Output is correct |
46 |
Correct |
142 ms |
16212 KB |
Output is correct |
47 |
Correct |
150 ms |
16260 KB |
Output is correct |
48 |
Correct |
146 ms |
16208 KB |
Output is correct |
49 |
Correct |
162 ms |
17236 KB |
Output is correct |
50 |
Correct |
167 ms |
16968 KB |
Output is correct |
51 |
Correct |
178 ms |
16864 KB |
Output is correct |
52 |
Correct |
186 ms |
19016 KB |
Output is correct |
53 |
Correct |
158 ms |
17736 KB |
Output is correct |
54 |
Correct |
156 ms |
17736 KB |
Output is correct |
55 |
Correct |
174 ms |
17992 KB |
Output is correct |
56 |
Correct |
221 ms |
20604 KB |
Output is correct |
57 |
Correct |
252 ms |
20808 KB |
Output is correct |
58 |
Correct |
269 ms |
21576 KB |
Output is correct |
59 |
Correct |
310 ms |
21736 KB |
Output is correct |
60 |
Correct |
224 ms |
21612 KB |
Output is correct |
61 |
Correct |
245 ms |
21320 KB |
Output is correct |
62 |
Correct |
239 ms |
20408 KB |
Output is correct |
63 |
Correct |
216 ms |
20552 KB |
Output is correct |
64 |
Correct |
201 ms |
20468 KB |
Output is correct |
65 |
Correct |
225 ms |
20552 KB |
Output is correct |
66 |
Correct |
208 ms |
20648 KB |
Output is correct |
67 |
Correct |
280 ms |
20640 KB |
Output is correct |