Submission #767079

# Submission time Handle Problem Language Result Execution time Memory
767079 2023-06-26T11:26:15 Z PoonYaPat Cat in a tree (BOI17_catinatree) C++14
0 / 100
62 ms 139612 KB
#include <bits/stdc++.h>
using namespace std;

int n,d;
vector<int> adj[200001];
deque<int> temp[200001];

void dfs(int x) {

    for (auto s : adj[x]) dfs(s);

    if (adj[x].size()==0) temp[x].push_front(1);
    else {
        int sum=1;
        if (temp[adj[x][0]].size()>=d) sum+=temp[adj[x][0]][d-1];
        swap(temp[x],temp[adj[x][0]]);

        for (int j=1; j<adj[x].size(); ++j) {
            int c=adj[x][j];
            if (temp[c].size()>=d) sum+=temp[c][d-1];
            if (temp[x].size()<temp[c].size()) swap(temp[x],temp[c]);

            for (int i=0; i<temp[c].size(); ++i) {
                if (2*(i+1)<d) {
                    if (temp[c].size()>=d-i-1) temp[x][i]=max(temp[x][i]+temp[c][d-2-i],temp[c][i]+temp[x][d-2-i]);
                    else if (temp[x].size()>=d-i-1) temp[x][i]=max(temp[x][i],temp[c][i]+temp[x][d-2-i]);
                    else temp[x][i]=max(temp[x][i],temp[c][i]);
                } else temp[x][i]+=temp[c][i];
            }
        }
        temp[x].push_front(sum);
    }
    while (temp[x].size()>d) temp[x].pop_back();
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>d;
    for (int i=1; i<n; ++i) {
        int x; cin>>x;
        adj[x].push_back(i);
    }
    dfs(0);
    int ans=0;
    for (int i=0; i<temp[0].size(); ++i) ans=max(ans,temp[0][i]);
    cout<<ans;
}

Compilation message

catinatree.cpp: In function 'void dfs(int)':
catinatree.cpp:15:35: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         if (temp[adj[x][0]].size()>=d) sum+=temp[adj[x][0]][d-1];
      |             ~~~~~~~~~~~~~~~~~~~~~~^~~
catinatree.cpp:18:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for (int j=1; j<adj[x].size(); ++j) {
      |                       ~^~~~~~~~~~~~~~
catinatree.cpp:20:31: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |             if (temp[c].size()>=d) sum+=temp[c][d-1];
      |                 ~~~~~~~~~~~~~~^~~
catinatree.cpp:23:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             for (int i=0; i<temp[c].size(); ++i) {
      |                           ~^~~~~~~~~~~~~~~
catinatree.cpp:25:39: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |                     if (temp[c].size()>=d-i-1) temp[x][i]=max(temp[x][i]+temp[c][d-2-i],temp[c][i]+temp[x][d-2-i]);
      |                         ~~~~~~~~~~~~~~^~~~~~~
catinatree.cpp:26:44: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |                     else if (temp[x].size()>=d-i-1) temp[x][i]=max(temp[x][i],temp[c][i]+temp[x][d-2-i]);
      |                              ~~~~~~~~~~~~~~^~~~~~~
catinatree.cpp:33:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     while (temp[x].size()>d) temp[x].pop_back();
      |            ~~~~~~~~~~~~~~^~
catinatree.cpp: In function 'int main()':
catinatree.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0; i<temp[0].size(); ++i) ans=max(ans,temp[0][i]);
      |                   ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 139612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 139612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 139612 KB Output isn't correct
2 Halted 0 ms 0 KB -