# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535915 | groshi | Cat in a tree (BOI17_catinatree) | C++17 | 1087 ms | 15364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
struct wi{
vector<int> Q;
int gdzie=0;
}*w;
int moge[1000000];
bool utnij[1000000];
void dfs(int x,int ile)
{
moge[x]=ile;
if(ile==1)
return;
for(int i=0;i<w[x].Q.size();i++)
{
int pom=w[x].Q[i];
if(utnij[w[pom].gdzie]==0 && moge[pom]<ile)
dfs(pom,ile-1);
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,d,x;
cin>>n>>d;
w=new wi[n+3];
vector<pair<int,int> > mam;
mam.push_back({0,0});
for(int i=1;i<n;i++)
{
cin>>x;
w[i].gdzie=w[x].gdzie+1;
w[i].Q.push_back(x);
w[x].Q.push_back(i);
mam.push_back({w[i].gdzie,i});
}
sort(mam.begin(),mam.end());
int wynik=0;
mam.push_back({-1,-1});
for(int i=mam.size()-2;i>=0;i--)
{
int jestem=mam[i].second;
if(mam[i].first<mam[i+1].first)
utnij[mam[i+1].first]=1;
if(moge[jestem]==0)
{
dfs(jestem,d);
wynik++;
}
}
cout<<wynik;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |