# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
451973 | 2021-08-03T14:59:51 Z | fadi57 | Cat in a tree (BOI17_catinatree) | C++14 | 13 ms | 23672 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); if(ans==1){ ans=-1; } cout<<ans+1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23672 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23672 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 23672 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |