Submission #925056

#TimeUsernameProblemLanguageResultExecution timeMemory
92505612345678Cat in a tree (BOI17_catinatree)C++17
100 / 100
292 ms250500 KiB
#include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int n, x, k; deque<int> dq[nx]; vector<int> d[nx]; void dfs(int u, int p) { dq[u].push_back(1); for (auto v:d[u]) { if (v==p) continue; dfs(v, u); dq[v].push_front(dq[v].front()); if (dq[v].size()>dq[u].size()) swap(dq[u], dq[v]); for (int i=0; i<dq[v].size(); i++) { int vu=dq[u][i]+((k-i<dq[v].size())?dq[v][max(i, k-i)]:0); int vv=dq[v][i]+((k-i<dq[u].size())?dq[u][max(i, k-i)]:0); dq[u][i]=max({dq[u][i], vu, vv}); } for (int i=dq[v].size()-2; i>=0; i--) dq[u][i]=max(dq[u][i], dq[u][i+1]); } } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>k; for (int i=1; i<n; i++) cin>>x, d[i].push_back(x), d[x].push_back(i); dfs(0, 0); cout<<dq[0].front(); }

Compilation message (stderr)

catinatree.cpp: In function 'void dfs(int, int)':
catinatree.cpp:19:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for (int i=0; i<dq[v].size(); i++)
      |                       ~^~~~~~~~~~~~~
catinatree.cpp:21:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             int vu=dq[u][i]+((k-i<dq[v].size())?dq[v][max(i, k-i)]:0);
      |                               ~~~^~~~~~~~~~~~~
catinatree.cpp:22:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |             int vv=dq[v][i]+((k-i<dq[u].size())?dq[u][max(i, k-i)]:0);
      |                               ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...