Submission #463940

#TimeUsernameProblemLanguageResultExecution timeMemory
463940blueCat in a tree (BOI17_catinatree)C++17
100 / 100
185 ms92704 KiB
#include <iostream> #include <deque> #include <vector> using namespace std; const int maxN = 200'000; int N, D, x, res = 0; vector<int> children[maxN]; deque<int> dfs(int u) { deque<int> res(1, 1); for(int v: children[u]) { deque<int> add = dfs(v); add.push_front(add.front()); if(res.size() < add.size()) swap(res, add); for(int i = 0; i < add.size(); i++) res[i] = max(res[i], max(add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0))); for(int i = add.size(); i >= 0; i--) if(i+1 < res.size()) res[i] = max(res[i], res[i+1]); } return res; } int main() { cin >> N >> D; for(int i = 1; i < N; i++) { cin >> x; children[x].push_back(i); } for(int r: dfs(0)) res = max(res, r); cout << res << '\n'; }

Compilation message (stderr)

catinatree.cpp: In function 'std::deque<int> dfs(int)':
catinatree.cpp:15:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i = 0; i < add.size(); i++) res[i] = max(res[i], max(add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0)));
      |                        ~~^~~~~~~~~~~~
catinatree.cpp:15:84: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i = 0; i < add.size(); i++) res[i] = max(res[i], max(add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0)));
      |                                                                                ~~~~^~~~~~~~~~~~
catinatree.cpp:15:136: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i = 0; i < add.size(); i++) res[i] = max(res[i], max(add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0)));
      |                                                                                                                                    ~~~~^~~~~~~~~~~~
catinatree.cpp:16:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for(int i = add.size(); i >= 0; i--) if(i+1 < res.size()) res[i] = max(res[i], res[i+1]);
      |                                                 ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...