#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define M 200000
#define Q 200000
int ii[M], jj[M];
int *ej[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;
}
char visited[N]; int cnt;
void dfs(int i) {
int o;
if (visited[i])
return;
visited[i] = 1, cnt++;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
dfs(j);
}
}
int main() {
static int dd[N], qu[N], hh[Q], ans[Q];
static char incr[M];
int n, m, q, g, h, i, j, d, o;
scanf("%d%d%d", &n, &m, &q);
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--;
ii[h] = i, jj[h] = j;
append(i, j), append(j, i);
}
for (i = 0; i < n; i++)
dd[i] = n;
dd[0] = 0, qu[cnt++] = 0;
for (h = 0; h < cnt; h++) {
i = qu[h], d = dd[i] + 1;
for (o = eo[i]; o--; ) {
j = ej[i][o];
if (dd[j] > d)
dd[j] = d, qu[cnt++] = j;
}
}
for (i = 0; i < n; i++)
free(ej[i]);
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0;
for (g = 0; g < q; g++) {
scanf("%d", &hh[g]), hh[g]--;
incr[hh[g]] = 1;
}
for (h = 0; h < m; h++) {
if (incr[h])
continue;
i = ii[h], j = jj[h];
if (dd[i] + 1 == dd[j])
append(i, j);
else if (dd[j] + 1 == dd[i])
append(j, i);
}
cnt = 0, dfs(0);
for (g = q - 1; g >= 0; g--) {
ans[g] = n - cnt;
h = hh[g], i = ii[h], j = jj[h];
if (dd[i] + 1 == dd[j]) {
append(i, j);
if (visited[i])
dfs(j);
} else if (dd[j] + 1 == dd[i]) {
append(j, i);
if (visited[j])
dfs(i);
}
}
for (g = 0; g < q; g++)
printf("%d\n", ans[g]);
return 0;
}
Compilation message
2016_ho_t3.c: In function 'append':
2016_ho_t3.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
14 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
2016_ho_t3.c: In function 'main':
2016_ho_t3.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d%d%d", &n, &m, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d", &i, &j), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.c:63:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d", &hh[g]), hh[g]--;
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
9 |
Correct |
87 ms |
10708 KB |
Output is correct |
10 |
Correct |
124 ms |
10684 KB |
Output is correct |
11 |
Correct |
94 ms |
10664 KB |
Output is correct |
12 |
Correct |
78 ms |
11140 KB |
Output is correct |
13 |
Correct |
83 ms |
11636 KB |
Output is correct |
14 |
Correct |
94 ms |
12804 KB |
Output is correct |
15 |
Correct |
48 ms |
11396 KB |
Output is correct |
16 |
Correct |
54 ms |
12128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
10764 KB |
Output is correct |
2 |
Correct |
81 ms |
10868 KB |
Output is correct |
3 |
Correct |
56 ms |
9344 KB |
Output is correct |
4 |
Correct |
101 ms |
10916 KB |
Output is correct |
5 |
Correct |
91 ms |
12776 KB |
Output is correct |
6 |
Correct |
84 ms |
12800 KB |
Output is correct |
7 |
Correct |
37 ms |
12124 KB |
Output is correct |
8 |
Correct |
45 ms |
12140 KB |
Output is correct |
9 |
Correct |
28 ms |
7196 KB |
Output is correct |
10 |
Correct |
29 ms |
6664 KB |
Output is correct |
11 |
Correct |
99 ms |
11812 KB |
Output is correct |
12 |
Correct |
90 ms |
11200 KB |
Output is correct |
13 |
Correct |
99 ms |
11160 KB |
Output is correct |
14 |
Correct |
96 ms |
11836 KB |
Output is correct |
15 |
Correct |
97 ms |
13636 KB |
Output is correct |
16 |
Correct |
90 ms |
13184 KB |
Output is correct |
17 |
Correct |
103 ms |
15180 KB |
Output is correct |
18 |
Correct |
74 ms |
14160 KB |
Output is correct |
19 |
Correct |
158 ms |
14800 KB |
Output is correct |
20 |
Correct |
98 ms |
15180 KB |
Output is correct |
21 |
Correct |
61 ms |
10772 KB |
Output is correct |
22 |
Correct |
54 ms |
10676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
9 |
Correct |
87 ms |
10708 KB |
Output is correct |
10 |
Correct |
124 ms |
10684 KB |
Output is correct |
11 |
Correct |
94 ms |
10664 KB |
Output is correct |
12 |
Correct |
78 ms |
11140 KB |
Output is correct |
13 |
Correct |
83 ms |
11636 KB |
Output is correct |
14 |
Correct |
94 ms |
12804 KB |
Output is correct |
15 |
Correct |
48 ms |
11396 KB |
Output is correct |
16 |
Correct |
54 ms |
12128 KB |
Output is correct |
17 |
Correct |
87 ms |
10764 KB |
Output is correct |
18 |
Correct |
81 ms |
10868 KB |
Output is correct |
19 |
Correct |
56 ms |
9344 KB |
Output is correct |
20 |
Correct |
101 ms |
10916 KB |
Output is correct |
21 |
Correct |
91 ms |
12776 KB |
Output is correct |
22 |
Correct |
84 ms |
12800 KB |
Output is correct |
23 |
Correct |
37 ms |
12124 KB |
Output is correct |
24 |
Correct |
45 ms |
12140 KB |
Output is correct |
25 |
Correct |
28 ms |
7196 KB |
Output is correct |
26 |
Correct |
29 ms |
6664 KB |
Output is correct |
27 |
Correct |
99 ms |
11812 KB |
Output is correct |
28 |
Correct |
90 ms |
11200 KB |
Output is correct |
29 |
Correct |
99 ms |
11160 KB |
Output is correct |
30 |
Correct |
96 ms |
11836 KB |
Output is correct |
31 |
Correct |
97 ms |
13636 KB |
Output is correct |
32 |
Correct |
90 ms |
13184 KB |
Output is correct |
33 |
Correct |
103 ms |
15180 KB |
Output is correct |
34 |
Correct |
74 ms |
14160 KB |
Output is correct |
35 |
Correct |
158 ms |
14800 KB |
Output is correct |
36 |
Correct |
98 ms |
15180 KB |
Output is correct |
37 |
Correct |
61 ms |
10772 KB |
Output is correct |
38 |
Correct |
54 ms |
10676 KB |
Output is correct |
39 |
Correct |
161 ms |
14896 KB |
Output is correct |
40 |
Correct |
125 ms |
14880 KB |
Output is correct |
41 |
Correct |
77 ms |
11312 KB |
Output is correct |
42 |
Correct |
119 ms |
14944 KB |
Output is correct |
43 |
Correct |
121 ms |
14864 KB |
Output is correct |
44 |
Correct |
122 ms |
14376 KB |
Output is correct |
45 |
Correct |
114 ms |
14456 KB |
Output is correct |
46 |
Correct |
58 ms |
12252 KB |
Output is correct |
47 |
Correct |
52 ms |
9460 KB |
Output is correct |
48 |
Correct |
51 ms |
9404 KB |
Output is correct |
49 |
Correct |
45 ms |
8188 KB |
Output is correct |
50 |
Correct |
58 ms |
8092 KB |
Output is correct |
51 |
Correct |
69 ms |
9252 KB |
Output is correct |
52 |
Correct |
49 ms |
8788 KB |
Output is correct |
53 |
Correct |
48 ms |
8156 KB |
Output is correct |
54 |
Correct |
57 ms |
8148 KB |
Output is correct |