답안 #463942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463942 2021-08-12T04:52:45 Z blue Cat in a tree (BOI17_catinatree) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <deque>
#include <vector>
int maxN = 200'000, N, D, x, res = 0;
std::vector<int> children[maxN];
std::deque<int> dfs(int u) {
    std::deque<int> res(1, 1);
    for(int v: children[u]) {
        auto 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] = std::max(res[i], std::max(add[i] + (D-i < res.size() ? res[std::max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[std::max(D-i, i)] : 0)));
        for(int i = add.size(); i >= 0; i--) if(i+1 < res.size()) res[i] = std::max(res[i], res[i+1]); }
    return res; }
int main() {
    std::cin >> N >> D;
    for(int i = 1; i < N; i++) { std::cin >> x; children[x].push_back(i); }
    for(int r: dfs(0)) res = std::max(res, r);
    std::cout << res << '\n'; }

Compilation message

catinatree.cpp:5:31: error: array bound is not an integer constant before ']' token
    5 | std::vector<int> children[maxN];
      |                               ^
catinatree.cpp: In function 'std::deque<int> dfs(int)':
catinatree.cpp:8:16: error: 'children' was not declared in this scope
    8 |     for(int v: children[u]) {
      |                ^~~~~~~~
catinatree.cpp:12:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for(int i = 0; i < add.size(); i++) res[i] = std::max(res[i], std::max(add[i] + (D-i < res.size() ? res[std::max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[std::max(D-i, i)] : 0)));
      |                        ~~^~~~~~~~~~~~
catinatree.cpp:12:94: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for(int i = 0; i < add.size(); i++) res[i] = std::max(res[i], std::max(add[i] + (D-i < res.size() ? res[std::max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[std::max(D-i, i)] : 0)));
      |                                                                                          ~~~~^~~~~~~~~~~~
catinatree.cpp:12:151: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for(int i = 0; i < add.size(); i++) res[i] = std::max(res[i], std::max(add[i] + (D-i < res.size() ? res[std::max(D-i, i)] : 0), res[i] + (D-i < add.size() ? add[std::max(D-i, i)] : 0)));
      |                                                                                                                                                   ~~~~^~~~~~~~~~~~
catinatree.cpp:13:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |         for(int i = add.size(); i >= 0; i--) if(i+1 < res.size()) res[i] = std::max(res[i], res[i+1]); }
      |                                                 ~~~~^~~~~~~~~~~~
catinatree.cpp: In function 'int main()':
catinatree.cpp:17:49: error: 'children' was not declared in this scope
   17 |     for(int i = 1; i < N; i++) { std::cin >> x; children[x].push_back(i); }
      |                                                 ^~~~~~~~