Submission #136207

#TimeUsernameProblemLanguageResultExecution timeMemory
136207thebesCat in a tree (BOI17_catinatree)C++14
0 / 100
6 ms4984 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 2e5+5; int N, D, i, x, d[MN], ans; vector<int> adj[MN]; void solve(int n){ vector<int> vec; for(auto v : adj[n]){ solve(v); vec.push_back(max(d[v]-1,0)); } sort(vec.begin(),vec.end(),[](int i,int j){return i>j;}); while(vec.size()>=2){ if(vec[0]+vec[1]<=D) break; else{ ans--; vec.erase(vec.begin()); } } if(vec.empty()||vec[0]==0){ ans ++; d[n] = D; } } int main(){ for(scanf("%d%d",&N,&D),i=2;i<=N;i++){ scanf("%d",&x); adj[x+1].push_back(i); } solve(1); printf("%d\n",ans); return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'int main()':
catinatree.cpp:29:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(scanf("%d%d",&N,&D),i=2;i<=N;i++){
         ~~~~~~~~~~~~~~~~~~~^~~~
catinatree.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...