Submission #29304

#TimeUsernameProblemLanguageResultExecution timeMemory
29304kdh9949Untitled (POI11_dyn)C++14
100 / 100
1606 ms30400 KiB
#include <bits/stdc++.h> using namespace std; int n, m, d[300010], ans; vector<int> e[300010]; int f(int x, int p, int c){ int t = 0, v = 0; for(auto &i : e[x]){ if(i != p){ int u = f(i, x, c); if(!u) continue; if(u > 0) v = max(v, u); else t = min(t, u); } } if(abs(t) >= c){ ans++; return c; } if(!v && !t) return -d[x]; if(v > abs(t)) return v - 1; return t - 1; } int can(int k){ ans = 0; if(f(1, 0, k) < 0) ans++; return ans <= m; } int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%d", d + i); for(int i = 0, x, y; i < n - 1; i++){ scanf("%d%d", &x, &y); e[x].push_back(y); e[y].push_back(x); } if(count(d + 1, d + n + 1, 1) <= m){ puts("0"); return 0; } int st = 1, en = n - 1; while(st <= en){ int mi = (st + en) / 2; if(can(mi)) en = mi - 1; else st = mi + 1; } printf("%d\n", st); }

Compilation message (stderr)

dyn.cpp: In function 'int main()':
dyn.cpp:33:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
dyn.cpp:34:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", d + i);
                                                ^
dyn.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...