# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
391290 | Ruxandra985 | Cat in a tree (BOI17_catinatree) | C++14 | 1 ms | 332 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 1510
using namespace std;
vector <int> v[DIMN];
deque <int> dq;
int dist[DIMN];
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , d , i , x , sol , ans , nod , vecin;
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);
}
sol = 0;
for (int j = 1 ; j <= n ; j++){
memset (dist , 0 , sizeof(dist));
dq.push_back(j);
dist[j] = 1;
ans = 0;
while (!dq.empty()){
nod = dq.front();
dq.pop_front();
if (dist[nod] % d == 1)
ans++;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i];
if (!dist[vecin]){
dist[vecin] = 1 + dist[nod];
dq.push_back(vecin);
}
}
}
sol = max(sol , ans);
}
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... |