제출 #451978

#제출 시각아이디문제언어결과실행 시간메모리
451978fadi57Cat in a tree (BOI17_catinatree)C++14
0 / 100
13 ms23756 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; }else{ depth--; } // cout<<node<<" "<<depth<<" "<<endl; 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); cout<<ans+1; }

컴파일 시 표준 에러 (stderr) 메시지

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