#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000
#define M 100000
int *ej[N], *ej_[N], eo[N], eo_[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int main() {
static int dd[N], qu1[N], qu2[N];
static char adj[N];
int n, m, cnt1, cnt2, s, a, b, h, h1, h2, i, j, k, o, o_, o1;
scanf("%d%d%d%d%d", &n, &m, &s, &a, &b), s--;
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < m; h++) {
scanf("%d%d", &i, &j), i--, j--;
append(i, j), append(j, i);
}
for (i = 0; i < n; i++) {
ej_[i] = (int *) malloc(eo[i] * sizeof *ej_[i]);
memcpy(ej_[i], ej[i], (eo_[i] = eo[i]) * sizeof *ej[i]);
}
memset(dd, 0x3f, n * sizeof *dd);
cnt1 = cnt2 = 0;
dd[s] = 0, qu1[cnt1++] = s;
h1 = 0, h2 = 0;
while (h1 < cnt1 || h2 < cnt2) {
i = h2 == cnt2 || h1 < cnt1 && dd[qu1[h1]] < dd[qu2[h2]] ? qu1[h1++] : qu2[h2++];
adj[i] = 1;
for (o = eo[i]; o--; ) {
j = ej[i][o];
adj[j] = 1;
if (dd[j] > dd[i] + a)
dd[j] = dd[i] + a, qu1[cnt1++] = j;
}
for (o = eo[i]; o--; ) {
j = ej[i][o];
o1 = 0;
for (o_ = 0; o_ < eo_[j]; o_++) {
k = ej_[j][o_];
if (adj[k])
ej_[j][o1++] = k;
else if (dd[k] > dd[i] + b)
dd[k] = dd[i] + b, qu2[cnt2++] = k;
}
eo_[j] = o1;
}
adj[i] = 0;
for (o = eo[i]; o--; ) {
j = ej[i][o];
adj[j] = 0;
}
}
for (i = 0; i < n; i++)
printf("%d\n", dd[i]);
return 0;
}
Compilation message
cen.c: In function 'append':
cen.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
13 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
cen.c: In function 'main':
cen.c:39:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
39 | i = h2 == cnt2 || h1 < cnt1 && dd[qu1[h1]] < dd[qu2[h2]] ? qu1[h1++] : qu2[h2++];
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cen.c:23:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d%d%d%d%d", &n, &m, &s, &a, &b), s--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cen.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d", &i, &j), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2404 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3420 KB |
Output is correct |
2 |
Correct |
4 ms |
3676 KB |
Output is correct |
3 |
Correct |
8 ms |
3676 KB |
Output is correct |
4 |
Correct |
5 ms |
3588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
5976 KB |
Output is correct |
2 |
Correct |
15 ms |
6584 KB |
Output is correct |
3 |
Correct |
14 ms |
5468 KB |
Output is correct |
4 |
Correct |
17 ms |
6424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
8532 KB |
Output is correct |
2 |
Correct |
22 ms |
8532 KB |
Output is correct |
3 |
Correct |
32 ms |
9512 KB |
Output is correct |
4 |
Correct |
31 ms |
9300 KB |
Output is correct |
5 |
Correct |
24 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
9812 KB |
Output is correct |
2 |
Correct |
22 ms |
8788 KB |
Output is correct |
3 |
Correct |
41 ms |
9616 KB |
Output is correct |
4 |
Correct |
30 ms |
9396 KB |
Output is correct |
5 |
Correct |
28 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
10880 KB |
Output is correct |
2 |
Correct |
31 ms |
11352 KB |
Output is correct |
3 |
Correct |
37 ms |
10324 KB |
Output is correct |
4 |
Correct |
30 ms |
9464 KB |
Output is correct |
5 |
Correct |
30 ms |
11600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
10492 KB |
Output is correct |
2 |
Correct |
33 ms |
11680 KB |
Output is correct |
3 |
Correct |
36 ms |
10836 KB |
Output is correct |
4 |
Correct |
30 ms |
9552 KB |
Output is correct |
5 |
Correct |
33 ms |
12368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
10832 KB |
Output is correct |
2 |
Correct |
36 ms |
12124 KB |
Output is correct |
3 |
Correct |
41 ms |
11956 KB |
Output is correct |
4 |
Correct |
29 ms |
9552 KB |
Output is correct |
5 |
Correct |
33 ms |
12372 KB |
Output is correct |