제출 #767310

#제출 시각아이디문제언어결과실행 시간메모리
767310PoonYaPatCat in a tree (BOI17_catinatree)C++14
100 / 100
255 ms244260 KiB
#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]; } for (int i=min((int)(temp[x].size())-2,(int)(temp[c].size())-1); i>=0; --i) temp[x][i]=max(temp[x][i],temp[x][i+1]); } temp[x].push_front(max(sum,temp[x][0])); } 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); cout<<temp[0].front(); }

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

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:35:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |     while (temp[x].size()>d) temp[x].pop_back();
      |            ~~~~~~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...