uppgb.c (712B)
1 #include "common.h" 2 3 uint64_t minok(tn *cp, uint64_t limit) { 4 uint64_t r = limit <= cp->size ? cp->size : UINT64_MAX; 5 size_t i; 6 for (i = 0; i < cp->children_n; i++) { 7 uint64_t tmp = minok(cp->children[i], limit); 8 if (tmp < r) 9 r = tmp; 10 } 11 return r; 12 } 13 14 int main(int argc, char **argv) { 15 char **lines; 16 size_t nlines = readlines(&lines, "input"); 17 18 size_t i; 19 for (i = 0; i < nlines; i++) { 20 if (lines[i][strlen(lines[i]) - 1] == '\n') 21 lines[i][strlen(lines[i]) - 1] = '\0'; 22 } 23 24 tn *root = parse_input(lines, nlines); 25 sum_sizes(root); 26 assert(root->size + 30000000 >= 70000000); 27 printf("%llu\n", minok(root, (root->size + 30000000) - 70000000)); 28 tn_cleartree(root); 29 }