Submission #29298

#TimeUsernameProblemLanguageResultExecution timeMemory
29298suhgyuho_williamUntitled (POI11_dyn)C++14
100 / 100
2393 ms29840 KiB
#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)

dyn.cpp: In function 'int main()':
dyn.cpp:48:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
dyn.cpp:50:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
dyn.cpp:54:23: 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...