# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
391326 | Ruxandra985 | Cat in a tree (BOI17_catinatree) | C++14 | 220 ms | 16316 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 <bits/stdc++.h>
#define DIMN 200010
using namespace std;
vector <int> v[DIMN];
vector <pair <int , int> > w;
int taken[DIMN] , lvl[DIMN];
void dfs (int nod , int tt , int still){
int i , vecin;
if (taken[nod] >= still)
return;
taken[nod] = still;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i];
if (vecin != tt && taken[vecin] < still - 1)
dfs(vecin , nod , still - 1);
}
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , d , i , x , sol , nod;
fscanf (fin,"%d%d",&n,&d);
for (i = 2 ; i <= n ; i++){
fscanf (fin,"%d",&x);
x++;
v[x].push_back(i);
v[i].push_back(x);
lvl[i] = 1 + lvl[x];
}
for (i = 1 ; i <= n ; i++)
w.push_back(make_pair(lvl[i] , i));
sort (w.begin() , w.end());
sol = 0;
while (!w.empty()){
nod = w.back().second;
w.pop_back();
if (taken[nod])
continue;
sol++;
dfs(nod , 0 , d);
}
fprintf (fout,"%d",sol);
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... |