제출 #463939

#제출 시각아이디문제언어결과실행 시간메모리
463939blueCat in a tree (BOI17_catinatree)C++17
100 / 100
179 ms92612 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++) { int opt1 = add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0); int opt2 = res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0); res[i] = max(res[i], max(opt1, opt2)); } 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'; }

컴파일 시 표준 에러 (stderr) 메시지

catinatree.cpp: In function 'std::deque<int> dfs(int)':
catinatree.cpp:16:26: 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 = 0; i < add.size(); i++)
      |                        ~~^~~~~~~~~~~~
catinatree.cpp:18:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             int opt1 = add[i] + (D-i < res.size() ? res[max(D-i, i)] : 0);
      |                                  ~~~~^~~~~~~~~~~~
catinatree.cpp:19:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |             int opt2 = res[i] + (D-i < add.size() ? add[max(D-i, i)] : 0);
      |                                  ~~~~^~~~~~~~~~~~
catinatree.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             if(i+1 < res.size())
      |                ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...