Submission #136209

#TimeUsernameProblemLanguageResultExecution timeMemory
136209thebesCat in a tree (BOI17_catinatree)C++14
100 / 100
116 ms18008 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(d[v]-1); } 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; } else d[n] = vec[0]; } 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:30: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:31: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...