# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
451975 | 2021-08-03T15:05:39 Z | fadi57 | Cat in a tree (BOI17_catinatree) | C++14 | 13 ms | 23756 KB |
#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); cout<<ans+1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |