Submission #451973

#TimeUsernameProblemLanguageResultExecution timeMemory
451973fadi57Cat in a tree (BOI17_catinatree)C++14
0 / 100
13 ms23672 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; const int mx=1e6+10; typedef long long ll; const int mod=1e9+7; const int MXm=22; #define F first #define S second const int inf=1e9+10; vector<int>adj[mx]; int n,d,ans; void dfs(int node,int depth,int par){ if(depth==0){ ans++; depth=d-1; } // cout<<node<<" "<<depth<<" "<<endl; depth--; for(auto it:adj[node]){ if(it==par){ continue; } dfs(it,depth,node); } return; } int main(){ cin>>n>>d; for(int i=1;i<n;i++){ int x; cin>>x; adj[i].push_back(x); adj[x].push_back(i); }int s; for(int i=0;i<n;i++){ if(adj[i].size()==1){ s=i; } } dfs(s,d,-1); if(ans==1){ ans=-1; } cout<<ans+1; }

Compilation message (stderr)

catinatree.cpp: In function 'int main()':
catinatree.cpp:52:10: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |       dfs(s,d,-1);
      |       ~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...