Submission #391290

#TimeUsernameProblemLanguageResultExecution timeMemory
391290Ruxandra985Cat in a tree (BOI17_catinatree)C++14
0 / 100
1 ms332 KiB
#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)

catinatree.cpp: In function 'int main()':
catinatree.cpp:34:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             for (i = 0 ; i < v[nod].size() ; i++){
      |                          ~~^~~~~~~~~~~~~~~
catinatree.cpp:13:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     fscanf (fin,"%d%d",&n,&d);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
catinatree.cpp:15:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         fscanf (fin,"%d",&x);
      |         ~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...