This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define avg(a, b) ((a + b) / 2)
#define ARR_SIZE 30005
typedef enum bool {
false, true
} bool;
int map_of_cities[ARR_SIZE][ARR_SIZE];
int visited_set[ARR_SIZE];
int num_not_satisfy(int num_workers, int city)
{
int i, child_city, children = map_of_cities[city][0], rec_res = 0, num_children = 0;
visited_set[city] = true;
for (i = 1; i <= children; i++) {
child_city = map_of_cities[city][i];
if (visited_set[child_city] == false) {
num_children++;
rec_res += num_not_satisfy(num_workers, child_city);
}
}
if ((num_children + rec_res - num_workers) <= 0) {
return 0;
} else {
return children + rec_res - num_workers;
}
}
int main()
{
int n, i, res, bsearch_start, bsearch_end, bsearch_mid, road_from, road_to;
scanf("%d", & n);
for (i = 0; i < ARR_SIZE; i++) {
map_of_cities[i][0] = 0;
}
for (i = 1; i < n; i++) {
scanf("%d %d", &road_from, & road_to);
map_of_cities[road_from][(map_of_cities[road_from][0]) + 1] = road_to;
map_of_cities[road_to][(map_of_cities[road_to][0]) + 1] = road_from;
map_of_cities[road_to][0] += 1;
map_of_cities[road_from][0] += 1;
}
for (bsearch_start = 0, bsearch_end = n; bsearch_start < bsearch_end; ) {
bsearch_mid = avg(bsearch_start, bsearch_end);
memset(visited_set, false, ARR_SIZE);
res = num_not_satisfy(bsearch_mid, 1);
if (res != 0) {
bsearch_start = bsearch_mid + 1;
} else {
bsearch_end = bsearch_mid;
}
}
res = bsearch_start;
printf("%d\n", res);
return 0;
}
Compilation message (stderr)
luk.c: In function 'main':
luk.c:52:3: warning: 'memset' used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
memset(visited_set, false, ARR_SIZE);
^~~~~~
luk.c:36:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", & n);
^~~~~~~~~~~~~~~~
luk.c:43:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &road_from, & road_to);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-start.o): In function `generic_start_main':
(.text+0x83): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_phdr' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-start.o): In function `generic_start_main':
(.text+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_phdr' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-start.o): In function `generic_start_main':
(.text+0xd5): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_phnum' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-start.o): In function `generic_start_main':
(.text+0x13e): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_osversion' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-start.o): In function `generic_start_main':
(.text+0x14c): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_osversion' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0x14): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_phdr' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0x20): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_phnum' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(dl-support.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0xac): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_static_dtv' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0xf4): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_static_dtv' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0xff): relocation truncated to fit: R_X86_64_PC32 against symbol `_dl_static_dtv' defined in COMMON section in /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o)
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-tls.o): In function `__libc_setup_tls':
(.text+0x11f): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status