# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29298 | suhgyuho_william | Untitled (POI11_dyn) | C++14 | 2393 ms | 29840 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>
#include <unistd.h>
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define lld long long
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define get gett
using namespace std;
int N,M,ans;
int a[300002],par[300002],lev[300002];
int cnt[300002];
bool check[300002];
vector<int> edge[300002];
int m,put;
int dfs(int x){
check[x] = true;
vector<int> tmp;
int big = -Inf;
for(auto &i : edge[x]){
if(check[i]) continue;
lev[i] = lev[x]+1;
par[i] = x;
big = max(big,dfs(i));
}
if(a[x] == 1) big = max(big,lev[x]);
cnt[par[x]] = max(cnt[par[x]],cnt[x]-1);
if(big <= lev[x]+cnt[x]-1) return -Inf;
if(big == lev[x]+m){
put++;
cnt[par[x]] = m;
return -Inf;
}else if(big == -Inf){
return -Inf;
}else return big;
}
int main(){
//freopen("input.txt","r",stdin);
scanf("%d %d",&N,&M);
for(int i=1; i<=N; i++){
scanf("%d",&a[i]);
}
for(int i=1; i<N; i++){
int x,y;
scanf("%d %d",&x,&y);
edge[x].pb(y);
edge[y].pb(x);
}
int l,r;
l = 0; r = N-1;
while(l <= r){
m = (l+r)/2;
memset(check,0,sizeof(check));
memset(cnt,0,sizeof(cnt));
put = 0;
if(dfs(1) != -Inf) put++;
if(put <= M){
ans = m;
r = m-1;
}else l = m+1;
}
printf("%d\n",ans);
return 0;
}
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... |