# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29307 | khsoo01 | Untitled (POI11_dyn) | C++11 | 2173 ms | 28372 KiB |
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<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 300005, inf = 1e9;
int n, m, cur, a[N], dt[N], lft[N], tnt;
vector<int> adj[N];
void solve (int C, int P) {
dt[C] = (a[C] ? 0 : -inf);
lft[C] = -inf;
for(auto &T : adj[C]) {
if(T == P) continue;
solve(T, C);
dt[C] = max(dt[C], dt[T] + 1);
lft[C] = max(lft[C], lft[T] - 1);
}
if(dt[C] <= lft[C]) dt[C] = -inf;
if(dt[C] >= cur) {tnt++; dt[C] = -inf; lft[C] = cur;}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
}
for(int i=1;i<n;i++) {
int A, B;
scanf("%d%d",&A,&B);
adj[A].push_back(B);
adj[B].push_back(A);
}
int S = 0, E = n;
while(S < E) {
cur = (S+E)/2; tnt = 0;
solve(1, 0);
if(dt[1] >= 0) tnt++;
tnt <= m ? E = cur : S = cur+1;
}
printf("%d\n", S);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |